{"record":{"id":"f41b52f973ae45cd","repo":"xai-org/x-algorithm","slug":"there-is-no-scope","errorCode":null,"errorMessage":"There is no scope","messagePattern":"There is no scope","errorType":"validation","errorClass":"SemanticCheckFailure","httpStatus":null,"severity":"error","filePath":"botmaker/src/java/com/twitter/botmaker/compiler/CompilerContext.java","lineNumber":224,"sourceCode":"  void addMacro(String funcName) {\n    curExpandedMacros.add(funcName);\n  }\n\n  void removeMacro(String funcName) {\n    curExpandedMacros.remove(funcName);\n  }\n\n  boolean containsMacro(String funcName) {\n    return curExpandedMacros.contains(funcName);\n  }\n\n  public void clearMacros() {\n    curExpandedMacros.clear();\n  }\n\n  long currentScopeId() throws SemanticCheckFailure {\n    if (scopeList.isEmpty()) {\n      throw new SemanticCheckFailure(\"There is no scope\");\n    }\n    if (enableContextScope) {\n      return currentScope().getId();\n    } else {\n      return ASTNode.CacheLevel.ConstantContextScope.scope;\n    }\n  }\n\n  private CompilerScope currentScope() throws SemanticCheckFailure {\n    if (scopeList.isEmpty()) {\n      throw new SemanticCheckFailure(\"There is no scope\");\n    }\n    return scopeList.getFirst();\n  }\n\n  CompilerScope addScope() throws SemanticCheckFailure {\n    CompilerScope scope =\n        new CompilerScope(NEXT_CONTEXT_ID.getAndIncrement(), currentScope());","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/botmaker/src/java/com/twitter/botmaker/compiler/CompilerContext.java#L206-L242","documentation":"currentScopeId() requires at least one active compiler scope; when the scope list is empty there is no lexical scope to attribute nodes to, so a SemanticCheckFailure is thrown. Scopes are pushed/popped as functions, lambdas, and blocks are compiled.","triggerScenarios":"Calling compile-time helpers (e.g. toAny, parameter, forEachNode, result, conditionParameter) from a context where no scope was pushed, e.g. compiling a node before entering a function/lambda body or after the scope stack was popped by an error path.","commonSituations":"Custom CompilerUnit implementations that build nodes outside a proper compile() invocation; misuse of the compiler API where addScope() was never called; early error paths that unwind scopes.","solutions":["Ensure node construction happens inside compile() of CompilerContext, which pushes a scope","Push a scope with addScope()/try-with-resources before requesting scope ids","Audit custom CompilerUnit implementations for node creation outside compilation"],"exampleFix":"// before\nlong id = ctx.currentScopeId(); // no scope pushed\n// after\ntry (CompilerScope s = ctx.addScope()) { long id = ctx.currentScopeId(); }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"catch (SemanticCheckFailure e) { if (\"There is no scope\".equals(e.getMessage())) { /* API misuse: ensure node construction happens inside compile() */ } }","preventionTips":["Never construct nodes outside an active CompilerContext.compile() call","Push scopes with addScope() in try-with-resources before scope-dependent work"],"tags":["botmaker","scope","internal-invariant"],"backgroundTag":"empty-scope-stack","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}