-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add error recovery #94
Draft
NebelNidas
wants to merge
22
commits into
FabricMC:dev
Choose a base branch
from
NebelNidas:error-recovery
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
0a6f345
Introduce basic error recovery
NebelNidas df21814
Add & use new constructors
NebelNidas c3eee6c
Overhaul `ColumnFileReader`
NebelNidas 0d6468f
Return null also when freshly encountering EOL as first char
NebelNidas c596950
Fix issue with start offset
NebelNidas 04e8563
Add changes to changelog
NebelNidas 93d976c
Merge branch 'upstream' into error-recovery
NebelNidas cdeb8b1
Merge 'ColumnFileReader-overhaul'
NebelNidas e5eff7c
Fix code style
NebelNidas 12dfc4d
Add tests
NebelNidas 4363dc9
Split error acceptors (sinks) and collectors
NebelNidas 802b125
Address reviews
NebelNidas c5d1133
Add `ErrorSink#noOp()` factory method
NebelNidas 21596a0
Rename remaining `errorCollector` occurrences to `errorSink`
NebelNidas 158d363
Add ProGuard test
NebelNidas 9922749
Add factory method to API for constructing a ThrowingErrorSink
NebelNidas adc9624
Add error recovery to JAM reader
NebelNidas f83227e
Add CSRG test
NebelNidas 795dd09
Add TSRG and TSRG v2 tests
NebelNidas 535a51d
Add Recaf Simple error recovery
NebelNidas 2ef5545
Add JOBF error recovery
NebelNidas 97fe03e
Merge upstream
NebelNidas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/net/fabricmc/mappingio/format/ErrorCollector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (c) 2024 FabricMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.fabricmc.mappingio.format; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import net.fabricmc.mappingio.format.ParsingError.Severity; | ||
|
||
public interface ErrorCollector extends ErrorSink { | ||
static ErrorCollector create() { | ||
return new ErrorCollector() { | ||
@Override | ||
public void add(Severity severity, String message) throws IOException { | ||
errors.add(ParsingError.create(severity, message)); | ||
} | ||
|
||
@Override | ||
public List<ParsingError> getErrors() { | ||
return errors; | ||
} | ||
|
||
private final List<ParsingError> errors = new ArrayList<>(); | ||
}; | ||
} | ||
|
||
List<ParsingError> getErrors(); | ||
NebelNidas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/net/fabricmc/mappingio/format/ErrorSink.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) 2023 FabricMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.fabricmc.mappingio.format; | ||
|
||
import java.io.IOException; | ||
|
||
import net.fabricmc.mappingio.format.ParsingError.Severity; | ||
|
||
public interface ErrorSink { | ||
static ErrorSink noOp() { | ||
return new ErrorSink() { | ||
@Override | ||
public void add(Severity severity, String message) { | ||
} | ||
}; | ||
} | ||
|
||
/** | ||
* Create an ErrorSink that throws an exception when an error | ||
* of the specified severity (or higher) is encountered. | ||
* | ||
* @param severity The severity to throw on. | ||
* @return The constructed ErrorSink instance. | ||
*/ | ||
static ErrorSink throwingOnSeverity(Severity severity) { | ||
return new ThrowingErrorSink(severity); | ||
} | ||
|
||
default void addInfo(String message) throws IOException { | ||
add(Severity.INFO, message); | ||
} | ||
|
||
default void addWarning(String message) throws IOException { | ||
add(Severity.WARNING, message); | ||
} | ||
|
||
default void addError(String message) throws IOException { | ||
add(Severity.ERROR, message); | ||
} | ||
|
||
void add(Severity severity, String message) throws IOException; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could the line number and column be optionally passed though? I see a lot of them include it in the message but might be nice to access this data programmatically? |
||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/net/fabricmc/mappingio/format/ParsingError.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (c) 2024 FabricMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.fabricmc.mappingio.format; | ||
|
||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
@ApiStatus.NonExtendable | ||
public interface ParsingError { | ||
static ParsingError create(Severity severity, String message) { | ||
return new ParsingError() { | ||
@Override | ||
public Severity getSeverity() { | ||
return severity; | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return message; | ||
} | ||
}; | ||
} | ||
|
||
Severity getSeverity(); | ||
|
||
String getMessage(); | ||
|
||
enum Severity { | ||
/** | ||
* When something's technically wrong but doesn't affect | ||
* parsing or the mapping data in any way. | ||
*/ | ||
INFO, | ||
/** | ||
* When element data is partially missing, but the rest of the element | ||
* could still be deciphered and it didn't have to be skipped entirely. | ||
* Or when an unknown top-level element is encountered. | ||
*/ | ||
WARNING, | ||
/** | ||
* An issue so severe that parsing of entire elements had to be skipped. | ||
* E.g. a class's/member's source name being absent. | ||
*/ | ||
ERROR | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/net/fabricmc/mappingio/format/ThrowingErrorSink.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (c) 2024 FabricMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.fabricmc.mappingio.format; | ||
|
||
import java.io.IOException; | ||
|
||
import net.fabricmc.mappingio.format.ParsingError.Severity; | ||
|
||
final class ThrowingErrorSink implements ErrorSink { | ||
ThrowingErrorSink(Severity severityToThrowAt) { | ||
this.severityToThrowAt = severityToThrowAt; | ||
} | ||
|
||
@Override | ||
public void add(Severity severity, String message) throws IOException { | ||
if (severity.compareTo(severityToThrowAt) >= 0) { | ||
throw new IOException(message); | ||
} | ||
} | ||
|
||
private final Severity severityToThrowAt; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why deprecate this, I think by default it should fail when it reads a malformed mapping file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To not have a dozen different overloads. You can use the
ErrorSink#noOp()
orErrorSink#throwingOnSeverity(...)
factory methods, just like you'd useProgressListener.none()
in EnigmaThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is ther why
new ThrowingErrorSink(Severity.WARNING)
is a bad default severity? Overloads is like a way to imply default arguments.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It hinders readability and is a pain to maintain. We already have up to five overloads per mapping reader, imagine we were to add an additional argument in the future, it would double the count again.
MappingReader#read
already has eight overloads, which I'm pretty sure starts getting confusing for consumers.At least the latter one would be remedied by #56, which gets rid of some of the overloads by removing implicit format detection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we have too many optional arguments, we might just use builders.