Skip to content

Commit

Permalink
Use throwException boolean argument to log a message or throw an erro…
Browse files Browse the repository at this point in the history
…r in case of incorrect input data

Signed-off-by: Romain Courtier <[email protected]>
  • Loading branch information
rcourtier committed Nov 15, 2024
1 parent c89707c commit 2825aeb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public String getName() {
@Override
public void apply(Network network, NamingStrategy namingStrategy, boolean throwException, ComputationManager computationManager, ReportNode reportNode) {
Generator generator = network.getGenerator(generatorId);
if (generator != null && !generator.getId().equals(generator.getRegulatingTerminal().getConnectable().getId())) {
if (generator == null) {
logOrThrow(throwException, "Generator '" + generatorId + "' not found");
} else if (!generator.getId().equals(generator.getRegulatingTerminal().getConnectable().getId())) {
setLocalRegulation(generator, reportNode);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.powsybl.iidm.modification;

import com.powsybl.commons.PowsyblException;
import com.powsybl.commons.report.ReportNode;
import com.powsybl.commons.test.TestUtil;
import com.powsybl.iidm.network.*;
Expand Down Expand Up @@ -38,6 +39,9 @@ void setLocalRegulationTest() throws IOException {
.withMessageTemplate("rootReportNode", "Set generators to local regulation").build();
new SetGeneratorToLocalRegulation("GEN1").apply(network, reportNode);
new SetGeneratorToLocalRegulation("GEN2").apply(network, reportNode);
SetGeneratorToLocalRegulation modification = new SetGeneratorToLocalRegulation("WRONG_ID");
PowsyblException e = assertThrows(PowsyblException.class, () -> modification.apply(network, true, reportNode));
assertEquals("Generator 'WRONG_ID' not found", e.getMessage());

// After applying the network modification, both generators regulate locally at 1.05 pu (21 kV).
assertEquals(gen1.getId(), gen1.getRegulatingTerminal().getConnectable().getId());
Expand Down

0 comments on commit 2825aeb

Please sign in to comment.