Skip to content
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

Ignore readline errors #42

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/henplus/HenPlus.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public void run() {
* sig) { System.out.println("caught: " + sig); } }; try {
* sun.misc.Signal.handle(new sun.misc.Signal("TSTP"), stoptest); }
* catch (Exception e) { // ignore. }
*
*
* end testing
*/
}
Expand Down Expand Up @@ -339,7 +339,22 @@ public String readlineFromFile() throws IOException {
private void storeLineInHistory() {
final String line = _historyLine.toString();
if (!"".equals(line) && !line.equals(_previousHistoryLine)) {
Readline.addToHistory(line);
try {
Readline.addToHistory(line);
} catch (Exception uee) {
// This error might happen if HenPlus is running
// on a system which doesn't have full encoding support --
// such as Alpine linux -- and the query (or query results?)
// include non-ASCII characters. This error will essetinally
// kill HenPlus, but it doesn't really affect the output,
// so we will ignore it.

// Notice:
// The exception thrown is really java.io.UnsupportedEncoding
// but due to it being thrown from the native code, it's not
// declared properly on the java interface so we can't
// specifically catch it here.
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the caught exception be runtime-tested to be an UnsupportedEncoding exception in order to make sure not to swallow anything else?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably. Haven't checked. The issue is, that the exception is thrown from the native code, so a bit of unwrapping magic would need to be done. I'll fix and recommit.

_previousHistoryLine = line;
}
_historyLine.setLength(0);
Expand Down Expand Up @@ -515,7 +530,7 @@ public CommandDispatcher getDispatcher() {

/**
* Provides access to the session manager. He maintains the list of opened sessions with their names.
*
*
* @return the session manager.
*/
public SessionManager getSessionManager() {
Expand Down Expand Up @@ -561,7 +576,7 @@ public void setDefaultPrompt() {
/**
* substitute the variables in String 'in', that are in the form $VARNAME or ${VARNAME} with the equivalent value that is found
* in the Map. Return the varsubstituted String.
*
*
* @param in
* the input string containing variables to be substituted (with leading $)
* @param variables
Expand Down