I'm running some mock code that looks like
const codeData = ... array of objects ...
const store = stores.open('codeData');
for (let code of codeData) {
logger.debug('Processing code data ' + code.code);
if (store.hasItemWithKey(code.code)) {
logger.debug('Attempting to load altered code ' + code.code);
let loadedCode = store.load(code.code)
logger.debug('Found altered code ' + loadedCode.code);
codes.push(loadedCode)
} else {
codes.push(code);
logger.debug('Using seeded code ' + code.code);
}
}
It's essentially merging changed data with our initially defined fixtures.
My issue is that it doesn't work and fails with an exception that looks like (lots more stacktrace but none really helpful)
Caused by: org.graalvm.polyglot.PolyglotException: The Context is already closed.
at com.oracle.truffle.polyglot.PolyglotEngineException.closedException(PolyglotEngineException.java:139) ~[truffle-api-22.3.5.jar:?]
at com.oracle.truffle.polyglot.PolyglotContextImpl.checkClosedOrDisposing(PolyglotContextImpl.java:1257) ~[truffle-api-22.3.5.jar:?]
at com.oracle.truffle.polyglot.PolyglotContextImpl.enterThreadChanged(PolyglotContextImpl.java:808) ~[truffle-api-22.3.5.jar:?]
at com.oracle.truffle.polyglot.PolyglotEngineImpl.enterCached(PolyglotEngineImpl.java:2026) ~[truffle-api-22.3.5.jar:?]
at com.oracle.truffle.polyglot.HostToGuestRootNode.execute(HostToGuestRootNode.java:109) ~[truffle-api-22.3.5.jar:?]
at com.oracle.truffle.polyglot.PolyglotMap.containsKey(PolyglotMap.java:115) ~[truffle-api-22.3.5.jar:?]
at io.gatehill.imposter.scripting.graalvm.proxy.InterceptingMap.hasMember(InterceptingMap.kt:64) ~[imposter-scripting-graalvm-4.7.0.jar:?]
at <js>.loadCodes(Unnamed:99) ~[?:?]
at <js>.getCode(Unnamed:110) ~[?:?]
at <js>.revokeCode(Unnamed:119) ~[?:?]
at <js>.:=>(Unnamed:162) ~[?:?]
at <js>.__run(Unnamed:33) ~[?:?]
Just prior to the exception the logs read.
16:15:40 INFO s./opt/imposter/config/mock-responses - Operation is api.resources.revoke_route
16:15:40 DEBUG s./opt/imposter/config/mock-responses - Processing code data NYGUAMNB46JQ
216:15:40 DEBUG s./opt/imposter/config/mock-responses - Attempting to load altered code NYGUAMNB46JQ
From this I think you can see that the failure is happening on the store.load line - which should only be hit if hasItemWithKey has returned true. hasItemWithKey is a function which I think is working as unless other code in the file is hit to call a store.save the else part of the if statement is processed - I get expected results and the log entry Using seeded code NYGUAMNB46JQ. I can also verify this is the broken line as removing it allows the code to work.
In summary
- Opening a store doesn't appear to cause an error.
- Saving to a store doesn't cause an error and, in fact, makes
hasItemWithKey return true.
- Loading all from the same store will return empty '{}' - even if a save operation has occured.
- Loading the item with the verified as saved key causes a Polyglot Exception.
Version: 4.7.0 Docker.
I'm running some mock code that looks like
It's essentially merging changed data with our initially defined fixtures.
My issue is that it doesn't work and fails with an exception that looks like (lots more stacktrace but none really helpful)
Just prior to the exception the logs read.
From this I think you can see that the failure is happening on the
store.loadline - which should only be hit ifhasItemWithKeyhas returned true.hasItemWithKeyis a function which I think is working as unless other code in the file is hit to call astore.savethe else part of theifstatement is processed - I get expected results and the log entryUsing seeded code NYGUAMNB46JQ. I can also verify this is the broken line as removing it allows the code to work.In summary
hasItemWithKeyreturn true.Version: 4.7.0 Docker.