Skip to content

Importing using wildcard export causes UNCAUGHT EXCEPTION #879

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

Open
undermethod opened this issue Apr 22, 2022 · 3 comments
Open

Importing using wildcard export causes UNCAUGHT EXCEPTION #879

undermethod opened this issue Apr 22, 2022 · 3 comments

Comments

@undermethod
Copy link

  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.

@azf20
Copy link
Contributor

azf20 commented Apr 25, 2022

Hi! I don't know if wildcard exports are supported by Assemblyscript? AssemblyScript/assemblyscript#27
cc @evaporei

@undermethod undermethod changed the title Importing from parent directories causes UNCAUGHT EXCEPTION Importing using wildcard export causes UNCAUGHT EXCEPTION Apr 25, 2022
@undermethod
Copy link
Author

undermethod commented Apr 25, 2022

wildcard exports

Good call! Simply updating to the non-indexed path worked:

import { Sample as SampleEvent } from "../../generated/SampleContractName/SampleContract";
import { SampleEntity } from "../../generated/schema";
import { STR_HARDCODED } from "../../../src/constants/sampleconst"; // <-- added path to avoid wildcard

export function handleSampleEvent(event: SampleEvent): void {
  const entity = new Entity(event.transaction.hash.toHex());
  entity.role = STR_HARDCODED; // <-- now able to reference without error
  entity.save();
}

I've renamed the issue accordingly.

@PaulRBerg
Copy link

Wildcard exports are supported by the latest version of AssemblyScript, as well as the @graphprotocol packages.

So I think this issue should be closed now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

4 participants