accordproject / template-archive

Smart Legal Contracts & Templating System
https://accordproject.org/projects/cicero/
Apache License 2.0
280 stars 119 forks source link

Extending Asset with Contract or Clause causes Archive error #791

Open martinhalford opened 1 year ago

martinhalford commented 1 year ago

Bug Report 🐛

The cicero archive command requires a valid package.json file which must contain either:

    "accordproject": {
      "template": "clause",
      "cicero": "^0.24.0",
      "runtime": "ergo"
    },

-- OR --

    "accordproject": {
      "template": "contract",
      "cicero": "^0.24.0",
      "runtime": "ergo"
    },

Note: Without this object in the package.json file, the cicero archive command throws the following expected error:

ERROR: /Users/martin/hello-world is not a valid cicero template. Make sure that package.json exists and that it has a cicero entry.

Assume you have the following grammar.tem.md file:

namespace hello@1.0.0

@template
concept HelloWorld {
    o String name
}

Attempting to execute cicero archive as a Clause template with this grammar.tem.md will result in the error:

ERROR: Failed to find an asset that extends org.accordproject.contract.Clause. The model for the template must contain a single asset that extends org.accordproject.contract.Clause.

Attempting to execute cicero archive as a Contract template with this grammar.tem.md will result in the error:

ERROR: Failed to find an asset that extends org.accordproject.contract.Contract. The model for the template must contain a single asset that extends org.accordproject.contract.Contract.

Attempted Fix 1:

Attempt to fix the issue by adding extends Contract or extends Clause to concept, like so:

namespace hello@1.0.0

@template
concept HelloWorld extends Contract {
    o String name
}

This results in the error:

ERROR: Could not find super type Contract File '/Users/martin/hello-world/model/model.cto': line 3 column 1, to line 6 column 2.

-- OR --

namespace hello@1.0.0

@template
concept HelloWorld extends Clause {
    o String name
}

This results in the error:

ERROR: Could not find super type Clause File '/Users/martin/hello-world/model/model.cto': line 3 column 1, to line 6 column 2.

Attempted Fix 2:

Add contract import to model.cto like so:

namespace hello@1.0.0

import org.accordproject.contract@0.2.0.Contract from https://models.accordproject.org/accordproject/contract@0.2.0.cto

@template
concept HelloWorld extends Contract {
    o String name
}

This results in the error:

ERROR: ConceptDeclaration (HelloWorld) cannot extend AssetDeclaration (Contract) File '/Users/martin/hello-world/model/model.cto': line 5 column 1, to line 8 column 2.

Context (Environment)

Summary

It seems that cicero archive requires an asset to extend either Contract or Clause but the concerto syntax no longer considers this as valid syntax.

Note: Also tried concerto compile --model ./hello-world/model/model.cto --target Rust and got same error.

dselman commented 1 year ago

We should use:

import { templatemarkutil } from '@accordproject/markdown-template';
...
templatemarkutil.findTemplateConcept(introspector, 'clause', templateConceptFqn);

To find the template class.

martinhalford commented 1 year ago

@mttrbrts @dselman - Not surprisingly, error occurs for other cicero commands too.

% cicero --version                                                   
0.24.1-20230722135139
% cicero compile --template ./hello-world --target Rust --output ./
1:18:13 pm - ERROR: Failed to find an asset that extends org.accordproject.contract.Contract. The model for the template must contain a single asset that extends org.accordproject.contract.Contract.
Error: Failed to find an asset that extends org.accordproject.contract.Contract. The model for the template must contain a single asset that extends org.accordproject.contract.Contract.
    at findTemplateModel (/Users/martin/.nvm/versions/node/v19.9.0/lib/node_modules/@accordproject/cicero-cli/node_modules/@accordproject/markdown-template/lib/templatemarkutil.js:108:11)
    at templateMarkTyping (/Users/martin/.nvm/versions/node/v19.9.0/lib/node_modules/@accordproject/cicero-cli/node_modules/@accordproject/markdown-template/lib/templatemarkutil.js:162:15)
    at ParserManager.initParser (/Users/martin/.nvm/versions/node/v19.9.0/lib/node_modules/@accordproject/cicero-cli/node_modules/@accordproject/markdown-template/lib/parsermanager.js:186:27)
    at ParserManager.buildParser (/Users/martin/.nvm/versions/node/v19.9.0/lib/node_modules/@accordproject/cicero-cli/node_modules/@accordproject/markdown-template/lib/parsermanager.js:198:12)
    at TemplateLoader.fromDirectory (/Users/martin/.nvm/versions/node/v19.9.0/lib/node_modules/@accordproject/cicero-cli/node_modules/@accordproject/cicero-core/src/templateloader.js:192:36)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
1:18:13 pm - INFO: Completed.