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

Filtering wollok base frames from stack trace & adding constants #172

Merged
merged 4 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const WOLLOK_EXTRA_STACK_TRACE_HEADER = 'Derived from TypeScript stack'

export const WOLLOK_BASE_PACKAGE = 'wollok.'
PalumboN marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion src/interpreter/runtimeModel.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}


Expand Down
3 changes: 2 additions & 1 deletion src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<Package>(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)(
Expand Down
3 changes: 2 additions & 1 deletion src/wre/lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const lang: Natives = {
Exception: {
*initialize(self: RuntimeObject): Execution<void> {
const stackTraceElements: RuntimeObject[] = []
for(const frame of this.frameStack.slice(0, -1)){
const customFrames = this.frameStack.slice(0, -1).filter(frame => frame.isCustom())
Copy link
Contributor

Choose a reason for hiding this comment

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

Esto decís que ya se hacía en Xtext, yo no me acordaba.

Pero entonces si el código del estudiante llama a algo de wollok (como un filter), esa llamada no se muestra en el stack?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

el filter no (y me parece que está bien), lo que se ve es código del alumne:

image

(lo de volar el código de Wollok fue un pedido de Passerini y con el diario del lunes estoy de acuerdo)

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!)
}
Expand Down
Loading