Skip to content

Commit e698ee4

Browse files
committed
+ Tighten LogViewer download
+ Harden Exception handling on Remote Exception cr: Jakub (pending)
1 parent 3ad70a4 commit e698ee4

File tree

3 files changed

+38
-11
lines changed

3 files changed

+38
-11
lines changed

grails-app/controllers/io/xh/hoist/admin/cluster/LogViewerAdminController.groovy

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,19 @@ class LogViewerAdminController extends BaseController {
8787
return
8888
}
8989

90-
render(
91-
file: ret.value,
92-
fileName: filename,
93-
contentType: 'application/octet-stream'
94-
)
90+
render(ret)
9591
}
9692

97-
static class Download extends ClusterRequest<File> {
93+
static class Download extends ClusterRequest<Map> {
9894
String filename
99-
100-
File doCall() {
95+
Map doCall() {
10196
if (!availableFiles[filename]) throwUnavailable(filename)
102-
return appContext.logReaderService.get(filename)
97+
def file = appContext.logReaderService.get(filename)
98+
[
99+
file: file.bytes,
100+
fileName: filename,
101+
contentType: 'application/octet-stream'
102+
]
103103
}
104104
}
105105

src/main/groovy/io/xh/hoist/cluster/ClusterRequest.groovy

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.xh.hoist.cluster
22

3+
import io.xh.hoist.exception.ClusterExecutionException
34
import io.xh.hoist.exception.InstanceNotAvailableException
45
import io.xh.hoist.log.LogSupport
56

@@ -17,15 +18,17 @@ abstract class ClusterRequest<T> implements Callable<ClusterResponse<T>>, LogSup
1718
}
1819
return new ClusterResponse(value: doCall())
1920
} catch (Throwable t) {
21+
def simpleName = this.class.simpleName
2022
try {
2123
exceptionHandler.handleException(
2224
exception: t,
2325
logTo: this,
24-
logMessage: [_action: this.class.simpleName]
26+
logMessage: [_action: simpleName]
2527
)
2628
} catch (Exception e) {
27-
// Even logging failing -- just catch quietly and return neatly to calling member.
29+
// Don't let logging ever prevent us from returning *actual* exception to caller.
2830
}
31+
t = new ClusterExecutionException("Failed to execute ${simpleName}: ${t.message}", t)
2932
return new ClusterResponse(exception: t)
3033
}
3134
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* This file belongs to Hoist, an application development toolkit
3+
* developed by Extremely Heavy Industries (www.xh.io | [email protected])
4+
*
5+
* Copyright © 2023 Extremely Heavy Industries Inc.
6+
*/
7+
8+
package io.xh.hoist.exception
9+
10+
11+
/**
12+
* Wrapper Exception to be returned from a failed ClusterResponse.
13+
*
14+
* Exceptions are supposed to be serializable but can cause problems in practice, especially in
15+
* Kryo. Note that we have already typically logged the actual exception on remote server.
16+
*/
17+
class ClusterExecutionException extends Exception {
18+
String causeName
19+
20+
ClusterExecutionException(String msg, Throwable t) {
21+
super(msg)
22+
causeName = t.class.simpleName
23+
}
24+
}

0 commit comments

Comments
 (0)