forked from beeware/voc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request beeware#711 from onyb/fix-exception-handling
Fix bugs in args attribute of exception objects
Showing
3 changed files
with
21 additions
and
31 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,21 @@ | ||
package org.python.exceptions; | ||
|
||
public class KeyError extends org.python.exceptions.LookupError { | ||
private String customMessage = null; | ||
public KeyError(org.python.Object[] args, java.util.Map<java.lang.String, org.python.Object> kwargs) { | ||
super(convertToReprIfOneArgument(args), kwargs); | ||
if (args.length == 1) { | ||
customMessage = args[0].__repr__().toString(); | ||
} | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
if (customMessage != null) { | ||
return customMessage; | ||
} | ||
return super.getMessage(); | ||
super(args, kwargs); | ||
} | ||
|
||
private static org.python.Object[] convertToReprIfOneArgument(org.python.Object[] args) { | ||
if (args.length == 1) { | ||
return new org.python.Object[] { args[0].__repr__() }; | ||
@org.python.Method( | ||
__doc__ = "Return str(self)." | ||
) | ||
public org.python.Object __str__() { | ||
if (this.args.value.size() == 1) { | ||
return this.args.value.get(0).__repr__(); | ||
} | ||
return args; | ||
return this.args.__str__(); | ||
} | ||
|
||
public KeyError(org.python.Object key) { | ||
super(key.__repr__().toString()); | ||
super(new org.python.Object[] {key}, null); | ||
} | ||
} |
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