Skip to content

TypeNotDefined error on a minimal schema w/ built-in types #496

@ericox

Description

@ericox

Before opening, please confirm:

Bug Category

Schemas and Validation

Describe the bug

A valid schema fails with a TypeNotDefined error when building a raw schema fragment.

Expected behavior

The schema fragment should be constructed w/o panicking.

Reproduction steps

  1. create a Cedar schema file on local disk with one entity
entity User {
   id: String,
    name: String,
 }
  1. run the code snipped below in a main().

Code Snippet

Given a schema with a single entity definition

entity User {
    id: String,
    name: String,
};

Loading a schema from a file,

  let buf = build_buffer();
  let mut u = Unstructured::new(&buf);
  let fragment = json_schema::Fragment::<RawName>::from_cedarschema_file(
        File::open(Path::new("data/quip.cedarschema")).unwrap(),
        Extensions::all_available(),
    )
    .unwrap()
    .0;
    let schema = Schema::from_raw_schemafrag(fragment, SETTINGS.clone(), &mut u);

panics on the Schema::from_raw_schemafrag(fragment, SETTINGS.clone(), &mut u) call with the following stack trace

thread 'main' panicked at /Users/emcx/cedar-spec/cedar-policy-generators/src/schema.rs:731:18:
called `Result::unwrap()` on an `Err` value: TypeNotDefined(TypeNotDefinedError(NonEmpty { head: ConditionalName { possibilities: NonEmpty { head: InternalName { id: Id("String"), path: [], loc: Some(Loc { span: SourceSpan { offset: SourceOffset(79), length: 6 }, src: "// Entities\n// All enums are modeled as just String here\nentity User {\n    id: String,\n    name: String,\n};" }) }, tail: [] }, reference_type: CommonOrEntity, raw: RawName(InternalName { id: Id("String"), path: [], loc: Some(Loc { span: SourceSpan { offset: SourceOffset(79), length: 6 }, src: "// Entities\n// All enums are modeled as just String here\nentity User {\n    id: String,\n    name: String,\n};" }) }) }, tail: [] }))
stack backtrace:
   0: rust_begin_unwind
             at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/std/src/panicking.rs:665:5
   1: core::panicking::panic_fmt
             at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/core/src/panicking.rs:74:14
   2: core::result::unwrap_failed
             at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/core/src/result.rs:1700:5
   3: core::result::Result<T,E>::unwrap
             at /Users/emcx/.rustup/toolchains/1.82.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/result.rs:1104:23
   4: cedar_policy_generators::schema::Schema::from_raw_nsdef
             at /Users/emcx/cedar-spec/cedar-policy-generators/src/schema.rs:728:13
   5: cedar_policy_generators::schema::Schema::from_raw_schemafrag
             at /Users/emcx/cedar-spec/cedar-policy-generators/src/schema.rs:814:25
   6: avp_query_data_gen::main
             at ./src/main.rs:58:18
   7: core::ops::function::FnOnce::call_once
             at /Users/emcx/.rustup/toolchains/1.82.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5

Log output

// Put your output below this line

Additional configuration

No response

Operating System

No response

Additional information and screenshots

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfuzz

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions