Changeset 16681 in josm


Ignore:
Timestamp:
2020-06-19T20:36:25+02:00 (4 years ago)
Author:
simon04
Message:

fix #19407 - SequenceCommand: catch throwable in sequence command and add more data (patch by taylor.smock, modified)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/command/SequenceCommand.java

    r16573 r16681  
    88import java.util.HashSet;
    99import java.util.Objects;
     10import java.util.stream.Collectors;
     11import java.util.stream.Stream;
    1012
    1113import javax.swing.Icon;
     
    1517import org.openstreetmap.josm.tools.ImageProvider;
    1618import org.openstreetmap.josm.tools.Utils;
     19import org.openstreetmap.josm.tools.bugreport.ReportedException;
    1720
    1821/**
     
    105108    @Override public boolean executeCommand() {
    106109        for (int i = 0; i < sequence.length; i++) {
    107             boolean result = sequence[i].executeCommand();
     110            boolean result;
     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);
     
    127135    protected final void undoCommands(int start) {
    128136        for (int i = start; i >= 0; --i) {
    129             sequence[i].undoCommand();
    130         }
     137            try {
     138                sequence[i].undoCommand();
     139            } catch (AssertionError | Exception e) {
     140                throw createReportedException(e, i);
     141            }
     142        }
     143    }
     144
     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", Stream.of(sequence)
     152                .map(o -> o.getClass().getCanonicalName())
     153                .map(String::valueOf)
     154                .collect(Collectors.joining(";", "[", "]")));
     155        exception.put("sequence_commands_descriptions", Stream.of(sequence)
     156                .map(Command::getDescriptionText)
     157                .collect(Collectors.joining(";", "[", "]")));
     158        return exception;
    131159    }
    132160
Note: See TracChangeset for help on using the changeset viewer.