Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

error handling

  • Loading branch information...
commit 4580f205885db7a7e7aff0cdc0b4d026323a2a04 1 parent a5b68f1
JP Moresmau authored
4 net.sf.eclipsefp.haskell-feature/feature.xml
View
@@ -137,14 +137,14 @@ available at http://www.eclipse.org/legal/epl-v10.html.
id="net.sf.eclipsefp.haskell.util"
download-size="0"
install-size="0"
- version="2.4.0"
+ version="2.4.3"
unpack="false"/>
<plugin
id="net.sf.eclipsefp.haskell.browser"
download-size="0"
install-size="0"
- version="2.4.1"
+ version="2.4.3"
unpack="false"/>
<plugin
2  net.sf.eclipsefp.haskell.browser/META-INF/MANIFEST.MF
View
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %bundleName
Bundle-SymbolicName: net.sf.eclipsefp.haskell.browser; singleton:=true
-Bundle-Version: 2.4.1
+Bundle-Version: 2.4.3
Bundle-Localization: plugin
Bundle-Activator: net.sf.eclipsefp.haskell.browser.BrowserPlugin
Require-Bundle: org.eclipse.ui;bundle-version="3.2.0",
47 net.sf.eclipsefp.haskell.browser/src/net/sf/eclipsefp/haskell/browser/client/StreamBrowserServer.java
View
@@ -10,6 +10,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
+import java.io.StringWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.zip.InflaterInputStream;
@@ -28,9 +29,9 @@
import net.sf.eclipsefp.haskell.browser.items.Module;
import net.sf.eclipsefp.haskell.browser.items.Packaged;
import net.sf.eclipsefp.haskell.browser.util.BrowserText;
+import net.sf.eclipsefp.haskell.util.DispatchWriter;
import net.sf.eclipsefp.haskell.util.FileUtil;
import net.sf.eclipsefp.haskell.util.LangUtil;
-import net.sf.eclipsefp.haskell.util.NullWriter;
import net.sf.eclipsefp.haskell.util.StreamRedirect;
import org.eclipse.core.runtime.IPath;
@@ -61,6 +62,9 @@
private boolean logError;
+ private StringWriter lastErrW=new StringWriter();
+ private DispatchWriter allErrWs=new DispatchWriter();
+
public StreamBrowserServer(IPath serverExecutable,boolean logError) throws Exception {
this.serverExecutable = serverExecutable;
this.declCache = new HashMap<String, Packaged<Declaration>[]>();
@@ -73,7 +77,11 @@ public StreamBrowserServer(IPath serverExecutable,boolean logError) throws Excep
public void setLogStream(Writer logStream) {
super.setLogStream(logStream);
if (logError){
- errorRedirect.setOutput(logStream);
+ allErrWs.getWriters().clear();
+ allErrWs.getWriters().add(lastErrW);
+ if (logError && logStream!=null){
+ allErrWs.getWriters().add(logStream);
+ }
}
}
@@ -89,8 +97,12 @@ public void startServer(boolean logError) throws Exception {
try {
process = builder.start();
out = process.getInputStream();
- Writer errorWriter=logError && logStream!=null?logStream:new NullWriter();
- errorRedirect=new StreamRedirect(new InputStreamReader(process.getErrorStream(),FileUtil.UTF8), errorWriter);
+ allErrWs.getWriters().clear();
+ allErrWs.getWriters().add(lastErrW);
+ if (logError && logStream!=null){
+ allErrWs.getWriters().add(logStream);
+ }
+ errorRedirect=new StreamRedirect(new InputStreamReader(process.getErrorStream(),FileUtil.UTF8), allErrWs);
errorRedirect.start();
/*out = new BufferedReader(new InputStreamReader(
process.getInputStream(), FileUtil.UTF8));*/
@@ -107,9 +119,7 @@ public String sendAndReceive(JSONObject input)
throws IOException {
synchronized(lock) {
String jsonInput = input.toString();
- log(">> " + jsonInput);
- in.write(jsonInput + "\n");
- in.flush();
+ sendCommand(jsonInput);
String response=getALine();
// String response = out.readLine();
//log(response);
@@ -124,9 +134,7 @@ public boolean sendAndReceiveOk(JSONObject input)
throws IOException {
synchronized(lock) {
String jsonInput = input.toString();
- log(">> " + jsonInput);
- in.write(jsonInput + "\n");
- in.flush();
+ sendCommand(jsonInput);
String response = null;
do {
@@ -141,9 +149,7 @@ public synchronized boolean sendAndReceiveBoolean(JSONObject input)
throws IOException {
synchronized(lock) {
String jsonInput = input.toString();
- log(">> " + jsonInput);
- in.write(jsonInput + "\n");
- in.flush();
+ sendCommand(jsonInput);
String response = null;
do {
@@ -155,13 +161,18 @@ public synchronized boolean sendAndReceiveBoolean(JSONObject input)
}
}
+ private void sendCommand(String command) throws IOException{
+ log(">> " + command);
+ lastErrW.getBuffer().setLength(0);
+ in.write(command + "\n");
+ in.flush();
+ }
+
public synchronized HoogleStatus sendAndReceiveStatus(JSONObject input)
throws IOException {
synchronized(lock) {
String jsonInput = input.toString();
- log(">> " + jsonInput);
- in.write(jsonInput + "\n");
- in.flush();
+ sendCommand(jsonInput);
HoogleStatus st=null;
String response = null;
do {
@@ -187,6 +198,10 @@ public String getALine() throws IOException{
return reader.readLine();
} catch (IOException e) {
BrowserPlugin.logError(BrowserText.error_read, e);
+ String lastErr=lastErrW.toString().trim();
+ if (lastErr!=null && lastErr.length()>0){
+ throw new IOException(lastErr);
+ }
throw e;
}
}
22 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/scion/ScionManager.java
View
@@ -814,14 +814,15 @@ public void done( final IJobChangeEvent event ) {
if (event.getResult().isOK()) {
loadHackageDatabase();
} else {
- Display.getDefault().syncExec( new Runnable() {
- @Override
- public void run() {
- MessageDialog.openError( Display.getDefault().getActiveShell(),
- UITexts.scionBrowserRebuildingDatabaseError_title,
- UITexts.scionBrowserRebuildingDatabaseError_message );
- }
- } );
+ // done by handling the job status
+// Display.getDefault().syncExec( new Runnable() {
+// @Override
+// public void run() {
+// MessageDialog.openError( Display.getDefault().getActiveShell(),
+// UITexts.scionBrowserRebuildingDatabaseError_title,
+// UITexts.scionBrowserRebuildingDatabaseError_message );
+// }
+// } );
}
super.done( event );
@@ -874,14 +875,15 @@ public void done( final IJobChangeEvent event ) {
preloadPrelude();
checkHoogleDataIsPresent();
} else {
- Display.getDefault().syncExec( new Runnable() {
+ // done by handling the job status
+ /*Display.getDefault().syncExec( new Runnable() {
@Override
public void run() {
MessageDialog.openError( Display.getDefault().getActiveShell(),
UITexts.scionBrowserRebuildingDatabaseError_title,
UITexts.scionBrowserRebuildingDatabaseError_message );
}
- } );
+ } );*/
}
super.done( event );
2  net.sf.eclipsefp.haskell.util/META-INF/MANIFEST.MF
View
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %bundleName
Bundle-SymbolicName: net.sf.eclipsefp.haskell.util
-Bundle-Version: 2.4.0
+Bundle-Version: 2.4.3
Bundle-Activator: net.sf.eclipsefp.haskell.util.Activator
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.core.resources,
60 net.sf.eclipsefp.haskell.util/src/net/sf/eclipsefp/haskell/util/DispatchWriter.java
View
@@ -0,0 +1,60 @@
+/**
+ * Copyright (c) 2012 by JP Moresmau
+ * This code is made available under the terms of the Eclipse Public License,
+ * version 1.0 (EPL). See http://www.eclipse.org/legal/epl-v10.html
+ */
+package net.sf.eclipsefp.haskell.util;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Dispatch write operations to several writers
+ * @author JP Moresmau
+ *
+ */
+public class DispatchWriter extends Writer {
+ List<Writer> writers=Collections.synchronizedList(new ArrayList<Writer>());
+
+ /**
+ * @return the writers
+ */
+ public List<Writer> getWriters() {
+ return writers;
+ }
+
+ /* (non-Javadoc)
+ * @see java.io.Writer#write(char[], int, int)
+ */
+ @Override
+ public void write(char[] cbuf, int off, int len) throws IOException {
+ for (Writer w:writers){
+ w.write(cbuf,off,len);
+ }
+
+ }
+
+ /* (non-Javadoc)
+ * @see java.io.Writer#flush()
+ */
+ @Override
+ public void flush() throws IOException {
+ for (Writer w:writers){
+ w.flush();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see java.io.Writer#close()
+ */
+ @Override
+ public void close() throws IOException {
+ for (Writer w:writers){
+ w.close();
+ }
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.