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

Be Able to Specify Path When Reporting Issue Through Reporter#report #69

Closed
philippfromme opened this issue Feb 7, 2022 · 10 comments · Fixed by #73
Closed

Be Able to Specify Path When Reporting Issue Through Reporter#report #69

philippfromme opened this issue Feb 7, 2022 · 10 comments · Fixed by #73
Assignees
Labels
enhancement New feature or request

Comments

@philippfromme
Copy link
Contributor

When using Reporter#report one can only provide the element ID and the error message. There is no way to provide additional properties e.g. the path of the property that has caused the error to be reported. I'd image something along the lines of:

Reporter.report('ServiceTask_1', '<zeebe:TaskDefinition> must have <zeebe:type> property', {
  path: [ 'extensionElements', 'values', 0, 'zeebe:type' ]
});

Adding an optional third argument wouldn't introduce any breaking changes.


Related to https://github.com/bpmn-io/internal-docs/issues/430

@philippfromme philippfromme added the enhancement New feature or request label Feb 7, 2022
@philippfromme philippfromme self-assigned this Feb 7, 2022
@philippfromme philippfromme added the in progress Currently worked on label Feb 7, 2022
@nikku
Copy link
Member

nikku commented Feb 7, 2022

To consider: Does a user need to construct the path herself? Or does bpmnlint take care of it?

@nikku
Copy link
Member

nikku commented Feb 7, 2022

The fundamental BPMNLint feature we're talking about here is: Be able to address sub-paths within an element.

@nikku
Copy link
Member

nikku commented Feb 7, 2022

Another way to think about it: We could also turn this thing upside down.

No path is introduced, instead elements are reported using the standard way:

Reporter.report(zeebeTaskDefinition, 'must have <zeebe:type> property');

// or

Reporter.report(buildPath(serviceTask, zebeeTaskDefinition), 'must have <zeebe:type> property');

@philippfromme
Copy link
Contributor Author

@nikku That's a good question. We could introduce this as a general feature, yes.

@philippfromme philippfromme added the ready Ready to be worked on label Feb 8, 2022 — with bpmn-io-tasks
@philippfromme philippfromme removed the in progress Currently worked on label Feb 8, 2022
@bpmn-io-tasks bpmn-io-tasks bot added in progress Currently worked on and removed ready Ready to be worked on labels Feb 28, 2022
@philippfromme
Copy link
Contributor Author

The utility for getting the path would have to be available in the respective plugins (e.g. bpmnlint-plugin-camunda-compat). I'm not sure what Reporter.report(buildPath(serviceTask, zebeeTaskDefinition), 'must have <zeebe:type> property'); would look like? Reporter.report([ 'ServiceTask_1', 'extensionElements', 0 'type' ], 'must have <zeebe:type> property');? That would introduce a breaking change and also require us to parse the path assuming the first key is the element's ID. I'm not a huge fan of that idea. My current approach looks like this:

class Reporter {
  constructor({ moddleRoot, rule }) {
    this.rule = rule;
    this.moddleRoot = moddleRoot;
    this.messages = [];
    this.report = this.report.bind(this);
  }

  report(id, message, options) {
    let report = {
      id,
      message
    };

    if (options) {
      report = {
        ...report,
        options // optional
      };
    }

    this.messages.push(report);
  }
}

The rule itself would look something like this:

// ...

return {
  message: 'Element of type <zeebe:TaskDefinition> must have <zeebe:type> property',
  path: [ ...getPath(taskDefinition, node), 'zeebe:type' ] // get the path of `taskDefinition` relative to `node`
};

As @smbea is going to start working on camunda/bpmnlint-plugin-camunda-compat#7 we need to come to an agreement regarding the solution for this issue.

@nikku What are your thoughts? Shall we have a chat about this?

@philippfromme philippfromme assigned smbea and unassigned philippfromme Feb 28, 2022
@nikku
Copy link
Member

nikku commented Feb 28, 2022

How would the CLI output look like in your idea?

@nikku
Copy link
Member

nikku commented Feb 28, 2022

We have to think this end-to-end, and if that means a major breaking change, I'd be fine with it.

@philippfromme
Copy link
Contributor Author

I guess you'd expect something similar to:

> bpmnlint invoice.bpmn

/Projects/process-application/resources/invoice.bpmn
  ServiceTask_1#extensionElements.values.0    error    Element of type <zeebe:TaskDefinition> must have <zeebe:type> property    camunda-cloud-1-0

✖ 1 problem (1 error, 0 warnings)

In that case we'd probably make the path concept known to bpmnlint. 🤔

@philippfromme
Copy link
Contributor Author

The API could still look like Reporter#report(id, message, path) with path being the only optional parameter. The CLI output could be formatted accordingly.

@nikku
Copy link
Member

nikku commented Mar 1, 2022

Had a short conversation with @philippfromme on the topic:

  • It makes sense to build path awareness into the core:
    • Reporter#report(id, message, path: [string|number][])
    • Report path in a sensible way via the CLI, too
  • We cannot rely on $parent for traversal (bpmnlint, bpmn-js-properties-panel)
    • Our usage of moddle does not guarantee that it is being maintained properly
    • If we decide to rely on it, our usage shall be fail-safe

Created bpmn-io/moddle#41 as a follow-up. I don't think we'll be able to tackle it in due time.


Sketch:

// getPath will be required not only by bpmnlint plugins (e.g. bpmnlint-plugin-camunda-compat)
// but also by bpmn-js-properties-panel
import { getPath } from '@bpmn-io/moddle-helpers';

// ...

reporter.report('ServiceTask_1', 'Task definition missing');
reporter.report('ServiceTask_1', 'Task definition type missing', [ 'extensionElements', 'values', 0, 'type' ]); // create path manually
reporter.report('ServiceTask_1', 'Task definition retries missing', [ ...getPath(moddleElement, parentModdleElement), 'retries' ]); // create path using utility

console.log(reporter.messages);

// [
//   {
//     id: 'ServiceTask_1',
//     message: 'Task definition missing'
//   },
//   {
//     id: 'ServiceTask_1',
//     message: 'Task definition type missing',
//     path: [ 'extensionElements', 'values', 0, 'type' ]
//   },
//   {
//     id: 'ServiceTask_1',
//     message: 'Task definition retries missing',
//     path: [ 'extensionElements', 'values', 0, 'retries' ]
//   }
// ]

CLI output:

> bpmnlint invoice.bpmn

/Projects/process-application/resources/invoice.bpmn
 ServiceTask_1    error    Task definition missing    camunda-cloud-1-0
 ServiceTask_1#extensionElements.values.0.type    error    Task definition type missing    camunda-cloud-1-0
 ServiceTask_1#extensionElements.values.0.retries    error    Task definition retries missing    camunda-cloud-1-0

✖ 3 problems (3 errors, 0 warnings)

@philippfromme philippfromme changed the title Be Able to Provide Additional Properties When Reporting Issue Through Reporter#report Be Able to Specify Path When Reporting Issue Through Reporter#report Mar 1, 2022
smbea pushed a commit that referenced this issue Mar 4, 2022
@bpmn-io-tasks bpmn-io-tasks bot added needs review Review pending and removed in progress Currently worked on labels Mar 4, 2022
smbea pushed a commit that referenced this issue Mar 4, 2022
smbea pushed a commit that referenced this issue Mar 4, 2022
smbea pushed a commit that referenced this issue Mar 7, 2022
philippfromme added a commit that referenced this issue Mar 7, 2022
@bpmn-io-tasks bpmn-io-tasks bot removed the needs review Review pending label Mar 7, 2022
philippfromme added a commit that referenced this issue Mar 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants