Ticket #19407: 19407.patch

File 19407.patch, 2.6 KB (added by taylor.smock, 4 years ago)
  • src/org/openstreetmap/josm/command/SequenceCommand.java

     
    77import java.util.Collection;
    88import java.util.HashSet;
    99import java.util.Objects;
     10import java.util.stream.Collectors;
     11import java.util.stream.Stream;
    1012
    1113import javax.swing.Icon;
    1214
     
    1416import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1517import org.openstreetmap.josm.tools.ImageProvider;
    1618import org.openstreetmap.josm.tools.Utils;
     19import org.openstreetmap.josm.tools.bugreport.ReportedException;
    1720
    1821/**
    1922 * A command consisting of a sequence of other commands. Executes the other commands
     
    104107
    105108    @Override public boolean executeCommand() {
    106109        for (int i = 0; i < sequence.length; i++) {
    107             boolean result = sequence[i].executeCommand();
     110            boolean result = false;
     111            try {
     112                result = sequence[i].executeCommand();
     113            } catch (AssertionError | Exception e) {
     114                throw createReportedException(e, i);
     115            }
    108116            if (!result && !continueOnError) {
    109117                undoCommands(i-1);
    110118                return false;
     
    126134
    127135    protected final void undoCommands(int start) {
    128136        for (int i = start; i >= 0; --i) {
    129             sequence[i].undoCommand();
     137            try {
     138                sequence[i].undoCommand();
     139            } catch (AssertionError | Exception e) {
     140                throw createReportedException(e, i);
     141            }
    130142        }
    131143    }
    132144
     145    private ReportedException createReportedException(Throwable e, int i) {
     146        ReportedException exception = new ReportedException(e);
     147        exception.startSection("sequence_information");
     148        exception.put("sequence_name", getDescriptionText());
     149        exception.put("sequence_command", sequence[i].getDescriptionText());
     150        exception.put("sequence_index", i);
     151        exception.put("sequence_commands", "[" +
     152        Stream.of(sequence).map(o -> o.getClass().getCanonicalName())
     153        .map(Object::toString).collect(Collectors.joining(";"))
     154        + "]");
     155        exception.put("sequence_commands_descriptions", "[" +
     156        Stream.of(sequence).map(Command::getDescriptionText)
     157        .collect(Collectors.joining(";"))
     158        + "]");
     159        return exception;
     160    }
     161
    133162    @Override
    134163    public void undoCommand() {
    135164        // We probably aborted this halfway though the execution sequence because of a sub-command error.