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

Accept strings as JSON #92

Open
adlerfaulkner opened this issue Apr 13, 2022 · 5 comments
Open

Accept strings as JSON #92

adlerfaulkner opened this issue Apr 13, 2022 · 5 comments
Labels

Comments

@adlerfaulkner
Copy link

Issue type:

  • 🐛 Bug

Description:

I am getting an error saying:

ErrorResourcesContext: Parameter value "@css:templates/main.html.ejs" is not of required range type "http://www.w3.org/1999/02/22-rdf-syntax-ns#JSON"

From this config:

{
     "@type": "EjsTemplateEngine",
     "EjsTemplateEngine:_template": "@css:templates/main.html.ejs"
}

Because the template arg of EjsTemplateEngine is supposed to be able to accept a string or a json object.

export class EjsTemplateEngine<T extends Dict<any> = Dict<any>> implements TemplateEngine<T> {
  /**
   * @param template - The default template @range {json}
   */
  public constructor(template?: Template) {
  }
}

Using a json field in this way errors because the string cannot be parsed by JSON.parse() here:

case IRIS_RDF.JSON:
try {
parsed = JSON.parse(value.value);
(<any>value.term).valueRaw = parsed;
} catch (error: unknown) {

JSON fields should accept strings because strings are valid JSON.


Environment:

components.js v4.5.0
nodejs v16.14.0

@github-actions
Copy link

Thanks for reporting!

@adlerfaulkner adlerfaulkner changed the title Strings are valid JSON Accept strings as JSON Apr 13, 2022
@rubensworks
Copy link
Member

@adlerfaulkner Looks like strings should indeed be accepted there.

Can you see any additional information about the root cause of the error in componentsjs-error-state.json?

@adlerfaulkner
Copy link
Author

I'm not sure what you want in componentsjs-error-state.json, all I see there are long lists of componentTypes, componentModules, importPaths, nodeModulePaths, and contexts.

Here's the full error output:

2022-04-14T06:29:54.017Z [Components.js] error: Detected fatal error. Generated 'componentsjs-error-state.json' with more information.
Could not create the server
Cause: Parameter value "@css:templates/setup/index.html.ejs" is not of required range type "http://www.w3.org/1999/02/22-rdf-syntax-ns#JSON"
parameter: {
  term: NamedNode {
    termType: 'NamedNode',
    value: 'https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/dist/util/templates/EjsTemplateEngine#EjsTemplateEngine_template'
  },
  properties: {
    'http://www.w3.org/2000/01/rdf-schema#range': [ [Resource] ],
    'http://www.w3.org/2000/01/rdf-schema#comment': [ [Resource] ],
    'https://linkedsoftwaredependencies.org/vocabularies/object-oriented#uniqueValue': [ [Resource] ],
    'http://www.w3.org/2000/01/rdf-schema#subClassOf': [],
    'https://linkedsoftwaredependencies.org/vocabularies/object-mapping#field': [],
    'https://linkedsoftwaredependencies.org/vocabularies/object-mapping#elements': [],
    'https://linkedsoftwaredependencies.org/vocabularies/object-oriented#defaultScoped': [],
    'https://linkedsoftwaredependencies.org/vocabularies/object-oriented#defaultValue': [],
    'https://linkedsoftwaredependencies.org/vocabularies/object-oriented#required': [],
    'https://linkedsoftwaredependencies.org/vocabularies/object-oriented#hasFixedValue': [],
    'https://linkedsoftwaredependencies.org/vocabularies/object-oriented#lazyValue': []
  }
}
ErrorResourcesContext: Parameter value "@css:templates/setup/index.html.ejs" is not of required range type "http://www.w3.org/1999/02/22-rdf-syntax-ns#JSON"
parameter: {
  term: NamedNode {
    termType: 'NamedNode',
    value: 'https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/dist/util/templates/EjsTemplateEngine#EjsTemplateEngine_template'
  },
  properties: {
    'http://www.w3.org/2000/01/rdf-schema#range': [ [Resource] ],
    'http://www.w3.org/2000/01/rdf-schema#comment': [ [Resource] ],
    'https://linkedsoftwaredependencies.org/vocabularies/object-oriented#uniqueValue': [ [Resource] ],
    'http://www.w3.org/2000/01/rdf-schema#subClassOf': [],
    'https://linkedsoftwaredependencies.org/vocabularies/object-mapping#field': [],
    'https://linkedsoftwaredependencies.org/vocabularies/object-mapping#elements': [],
    'https://linkedsoftwaredependencies.org/vocabularies/object-oriented#defaultScoped': [],
    'https://linkedsoftwaredependencies.org/vocabularies/object-oriented#defaultValue': [],
    'https://linkedsoftwaredependencies.org/vocabularies/object-oriented#required': [],
    'https://linkedsoftwaredependencies.org/vocabularies/object-oriented#hasFixedValue': [],
    'https://linkedsoftwaredependencies.org/vocabularies/object-oriented#lazyValue': []
  }
}
    at ParameterPropertyHandlerRange.throwIncorrectTypeError (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/preprocess/parameterproperty/ParameterPropertyHandlerRange.js:87:15)
    at ParameterPropertyHandlerRange.captureType (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/preprocess/parameterproperty/ParameterPropertyHandlerRange.js:79:30)
    at ParameterPropertyHandlerRange.handle (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/preprocess/parameterproperty/ParameterPropertyHandlerRange.js:18:18)
    at ParameterHandler.applyParameterValues (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/preprocess/ParameterHandler.js:50:33)
    at ConfigPreprocessorComponentMapped.getParameterValue (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/preprocess/ConfigPreprocessorComponentMapped.js:56:46)
    at ConstructorArgumentsElementMappingHandlerList.handle (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerList.js:23:40)
    at ConfigPreprocessorComponentMapped.applyConstructorArgumentsParameters (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/preprocess/ConfigPreprocessorComponentMapped.js:42:32)
    at ConfigPreprocessorComponentMapped.transformConstructorArguments (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/preprocess/ConfigPreprocessorComponentMapped.js:36:21)
    at ConfigPreprocessorComponentMapped.transform (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/preprocess/ConfigPreprocessorComponent.js:85:47)
    at ConfigConstructorPool.getRawConfig (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/construction/ConfigConstructorPool.js:70:52)
    at ConfigConstructorPool.instantiate (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/construction/ConfigConstructorPool.js:46:34)
    at ArgumentConstructorHandlerReference.handle (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/construction/argument/ArgumentConstructorHandlerReference.js:22:56)
    at ConfigConstructor.getArgumentValue (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/construction/ConfigConstructor.js:55:32)
    at /Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/construction/argument/ArgumentConstructorHandlerArray.js:18:38
    at Array.map (<anonymous>)
    at ArgumentConstructorHandlerArray.handle (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/construction/argument/ArgumentConstructorHandlerArray.js:14:73)

@adlerfaulkner
Copy link
Author

adlerfaulkner commented Apr 14, 2022

When I put console.debug for the error on line 79 of ParameterPropertyHandlerRange.js (the js version in my node_modules folder), I get:

SyntaxError: Unexpected token @ in JSON at position 0
    at JSON.parse (<anonymous>)
    at ParameterPropertyHandlerRange.captureType (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/preprocess/parameterproperty/ParameterPropertyHandlerRange.js:75:39)
    at ParameterPropertyHandlerRange.handle (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/preprocess/parameterproperty/ParameterPropertyHandlerRange.js:18:18)
    at ParameterHandler.applyParameterValues (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/preprocess/ParameterHandler.js:50:33)
    at ConfigPreprocessorComponentMapped.getParameterValue (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/preprocess/ConfigPreprocessorComponentMapped.js:56:46)
    at ConstructorArgumentsElementMappingHandlerList.handle (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerList.js:23:40)
    at ConfigPreprocessorComponentMapped.applyConstructorArgumentsParameters (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/preprocess/ConfigPreprocessorComponentMapped.js:42:32)
    at ConfigPreprocessorComponentMapped.transformConstructorArguments (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/preprocess/ConfigPreprocessorComponentMapped.js:36:21)
    at ConfigPreprocessorComponentMapped.transform (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/preprocess/ConfigPreprocessorComponent.js:85:47)
    at ConfigConstructorPool.getRawConfig (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/construction/ConfigConstructorPool.js:70:52)
    at ConfigConstructorPool.instantiate (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/construction/ConfigConstructorPool.js:46:34)
    at ArgumentConstructorHandlerReference.handle (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/construction/argument/ArgumentConstructorHandlerReference.js:22:56)
    at ConfigConstructor.getArgumentValue (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/construction/ConfigConstructor.js:55:32)
    at /Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/construction/argument/ArgumentConstructorHandlerArray.js:18:38
    at Array.map (<anonymous>)
    at ArgumentConstructorHandlerArray.handle (/Users/adlerfaulkner/community-server/node_modules/componentsjs/lib/construction/argument/ArgumentConstructorHandlerArray.js:14:73)

which is the error produced by JSON.parse("@css:templates/setup/index.html.ejs")

@rubensworks
Copy link
Member

This may be another JSON-parsing-related bug in the JSON-LD parser.
It looks like the quotes are missing.

We would expect JSON.parse("\"@css:templates/setup/index.html.ejs\"") to be called, and not JSON.parse("@css:templates/setup/index.html.ejs").
The expected output by the parser should be "\"@css:templates/setup/index.html.ejs\""

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants