diff --git a/src/constants.ts b/src/constants.ts new file mode 100644 index 00000000..74519201 --- /dev/null +++ b/src/constants.ts @@ -0,0 +1,3 @@ +export const WOLLOK_EXTRA_STACK_TRACE_HEADER = 'Derived from TypeScript stack' + +export const WOLLOK_BASE_PACKAGE = 'wollok.' \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 2e179bda..dd8e0bd9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -19,6 +19,7 @@ function buildEnvironment(files: List<{ name: string, content: string }>, baseEn }), baseEnvironment) } +export * from './constants' export * from './model' export * from './interpreter/runtimeModel' export { diff --git a/src/interpreter/runtimeModel.ts b/src/interpreter/runtimeModel.ts index 574da2b4..7b07dba4 100644 --- a/src/interpreter/runtimeModel.ts +++ b/src/interpreter/runtimeModel.ts @@ -1,3 +1,4 @@ +import { WOLLOK_BASE_PACKAGE, WOLLOK_EXTRA_STACK_TRACE_HEADER } from '../constants' import { v4 as uuid } from 'uuid' import { getPotentiallyUninitializedLazy } from '../decorators' import { get, is, last, List, match, raise, when } from '../extensions' @@ -50,7 +51,7 @@ export class WollokException extends Error { get message(): string { const error: RuntimeObject = this.instance error.assertIsException() - return `${error.innerValue ? error.innerValue.message : error.get('message')?.innerString ?? ''}\n${this.wollokStack}\n Derived from TypeScript stack` + return `${error.innerValue ? error.innerValue.message : error.get('message')?.innerString ?? ''}\n${this.wollokStack}\n ${WOLLOK_EXTRA_STACK_TRACE_HEADER}` } // TODO: Do we need to take this into consideration for Evaluation.copy()? This might be inside Exception objects @@ -152,6 +153,11 @@ export class Frame extends Context { override toString(): string { return `${this.description}(${this.sourceInfo})` } + + isCustom(): boolean { + const module = this.node.ancestors.find(ancestor => ancestor.is(Module)) as Module + return !module?.fullyQualifiedName?.startsWith(WOLLOK_BASE_PACKAGE) && !this.node.is(Environment) + } } diff --git a/src/validator.ts b/src/validator.ts index 91226c28..3d9c1302 100644 --- a/src/validator.ts +++ b/src/validator.ts @@ -18,6 +18,7 @@ // - Level could be different for the same Expectation on different nodes // - Problem could know how to convert to string, receiving the interpolation function (so it can be translated). This could let us avoid having parameters. // - Good default for simple problems, but with a config object for more complex, so we know what is each parameter +import { WOLLOK_BASE_PACKAGE } from './constants' import { count, TypeDefinition, duplicates, is, isEmpty, last, List, match, notEmpty, when } from './extensions' // - Unified problem type import { Assignment, Body, Catch, Class, Code, Describe, Entity, Expression, Field, If, Import, @@ -703,7 +704,7 @@ const usesReservedWords = (node: Class | Singleton | Variable | Field | Paramete const parent = node.ancestors.find(ancestor => ancestor.is(Package)) as Package | undefined const wordsReserved = LIBRARY_PACKAGES.flatMap(libPackage => node.environment.getNodeByFQN(libPackage).members.map(_ => _.name)) wordsReserved.push('wollok') - return !!parent && !parent.fullyQualifiedName.includes('wollok.') && wordsReserved.includes(node.name) + return !!parent && !parent.fullyQualifiedName.includes(WOLLOK_BASE_PACKAGE) && wordsReserved.includes(node.name) } const supposedToReturnValue = (node: Node): boolean => match(node.parent)( diff --git a/src/wre/lang.ts b/src/wre/lang.ts index b55e0c62..31bc9856 100644 --- a/src/wre/lang.ts +++ b/src/wre/lang.ts @@ -11,7 +11,8 @@ const lang: Natives = { Exception: { *initialize(self: RuntimeObject): Execution { const stackTraceElements: RuntimeObject[] = [] - for(const frame of this.frameStack.slice(0, -1)){ + const customFrames = this.frameStack.slice(0, -1).filter(frame => frame.isCustom()) + for(const frame of customFrames){ const stackTraceElement = yield* this.send('createStackTraceElement', self, yield* this.reify(frame.description), yield* this.reify(frame.sourceInfo)) stackTraceElements.unshift(stackTraceElement!) }