Skip to content

Importing using wildcard export causes UNCAUGHT EXCEPTION #879

Open
@undermethod

Description

@undermethod
  1. root git dir contains (among others) /src/constants/ dir, itself containing:
    • sampleconst.ts:
      export const STR_HARDCODED = "StrVal";
      along with index.ts:
      export * from "sampleconst.ts";
  2. child dir /subgraph/ contains (among others):
    • package.json
      • "@graphprotocol/graph-cli": "^0.29.0",
      • "@graphprotocol/graph-ts": "^0.26.0",
    • schema, manifest, lock file, locally installed dependencies
    • /src/ (among others) contains:
      • mappings/samplemapping.ts containing
        import { Sample as SampleEvent } from "../../generated/SampleContractName/SampleContract";
        import { SampleEntity } from "../../generated/schema";
        import { STR_HARDCODED } from "../../../src/constants"; // <-- issue is here
        
        export function handleSampleEvent(event: SampleEvent): void {
          const entity = new Entity(event.transaction.hash.toHex());
          entity.role = STR_HARDCODED;
          entity.save();
        }
  3. performing a codegen succeeds
  4. performing a build fails:
    Error: Failed to compile data source mapping: assertion failed
        at Compiler._compileDataSourceMapping (/Users/path/subgraph/node_modules/@graphprotocol/graph-cli/src/compiler/index.js:307:13)
        at /Users/path/subgraph/node_modules/@graphprotocol/graph-cli/src/compiler/index.js:216:20
        at updateInDeepMap (/Users/path/subgraph/node_modules/immutable/dist/immutable.js:1971:22)
        at updateInDeepMap (/Users/path/subgraph/node_modules/immutable/dist/immutable.js:1980:23)
        at updateInDeepMap (/Users/path/subgraph/node_modules/immutable/dist/immutable.js:1980:23)
        at Map.updateIn (/Users/path/subgraph/node_modules/immutable/dist/immutable.js:1278:26)
        at /Users/path/subgraph/node_modules/@graphprotocol/graph-cli/src/compiler/index.js:215:24
        at /Users/path/subgraph/node_modules/immutable/dist/immutable.js:3016:46
        at List.__iterate (/Users/path/subgraph/node_modules/immutable/dist/immutable.js:2206:13)
        at IndexedIterable.mappedSequence.__iterateUncached (/Users/path/subgraph/node_modules/immutable/dist/immutable.js:3015:23)
    UNCAUGHT EXCEPTION: Error: The AssemblyScript compiler crashed when compiling this file: 'src/mappings/samplemapping.ts'
    Suggestion: try to comment the whole file and uncomment it little by little while re-running the graph-cli until you isolate the line where the problem happens.
    Also, please contact us so we can make the CLI better by handling errors like this. You can reach out in any of these links:
    - Discord channel: https://discord.gg/eM8CA6WA9r
    - Github issues: https://github.com/graphprotocol/graph-cli/issues
    error Command failed with exit code 1.
    
  5. simply commenting out the above import and replacing with the hardcoded string itself:
    import { Sample as SampleEvent } from "../../generated/SampleContractName/SampleContract";
    import { SampleEntity } from "../../generated/schema";
    // import { STR_HARDCODED } from "../../../src/constants"; // <-- no longer import from dir parent to subgraph
    
    export function handleSampleEvent(event: SampleEvent): void {
      const entity = new Entity(event.transaction.hash.toHex());
      entity.role = "StrVal"; // replaced with raw hardcoded string no longer imported
      entity.save();
    }
  6. both codegen and build succeed

Let me know if any other info would help.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions