LinkedSoftwareDependencies / Components.js

🧩 A semantic dependency injection framework
https://componentsjs.readthedocs.io/
Other
41 stars 6 forks source link

Accept strings as JSON #92

Open adlerfaulkner opened 2 years ago

adlerfaulkner commented 2 years ago

Issue type:


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: https://github.com/LinkedSoftwareDependencies/Components.js/blob/4c14d40be7d1cd6a596085ccedca6b55a5af4ed2/lib/preprocess/parameterproperty/ParameterPropertyHandlerRange.ts#L144-L148

JSON fields should accept strings because strings are valid JSON.


Environment:

components.js v4.5.0 nodejs v16.14.0

github-actions[bot] commented 2 years ago

Thanks for reporting!

rubensworks commented 2 years ago

@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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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\""