aurelia / aurelia/binding

REQUEST: downgrade 'No Aurelia APIs are defined for the element: "xxx".' from thrown error to warning message

Open
#676 6 comments 0 reactions 0 assignees View on GitHub
awaiting-feedback
Dominant language
JavaScript
Stars
110
Forks
98
PR merge metrics
No merged PRs in 30d

Description

**I'm submitting a feature request**

currently aurelia enhance is falling over when it gets elements with element/controller/view-model/view which are not defined

and it breaks the bootstraping of aurelia

caused by this code

```
function getAU(element) {
let au = element.au;

if (au === undefined) {
throw new Error(`No Aurelia APIs are defined for the element: "${element.tagName}".`);
}

return au;
}
node_modules\aurelia-binding\dist\aurelia-binding.js
```

is there any chance this could be sent as a warning or try/catched into a warning

currently monkey patched with this in dev which not ideal, to stopping html inserted ahead of js components being deployed breaking builds

```
// Monkey Patch : turn thrown error into error message
import {NameExpression} from 'aurelia-binding';
function getAU(element) {
var au = element.au;

if (au === undefined) {
// assumption that aurelia instance available
aurelia.logger.error('No Aurelia APIs are defined for the element: "' + element.tagName + '".');
// throw new Error('No Aurelia APIs are defined for the element: "' + element.tagName + '".');
}
return au;
}
NameExpression.locateAPI = function locateAPI(element, apiName) {
switch (apiName) {
case 'element':
return element;
case 'controller':
return getAU(element).controller;
case 'view-model':
return getAU(element).controller.viewModel;
case 'view':
return getAU(element).controller.view;
default:
var target = getAU(element)[apiName];

if (target === undefined) {
throw new Error('Attempted to reference "' + apiName + '", but it was not found amongst the target\'s API.');
}

return target.viewModel;
}
};
```

* **Library Version:**
ALL

**Please tell us about your environment:**
* **Operating System:**
NA

* **Node Version:**
NA

* **JSPM OR Webpack AND Version**
NA

* **Browser:**
NA

* **Language:**
NA

**Current behavior:**

**Expected/desired behavior:**

* **What is the expected behavior?**
Aurelia should be robust and not fall over / aka cascade exception, when finding dom without Aurelia API

* **What is the motivation / use case for changing the behavior?**
Aurelia should be tough and handle not ideal html gracefully (but still call out error and the situations)

Contributor guide

Open the contributing guide

Research direction

Start with getAU and NameExpression.locateAPI in the referenced node_modules/aurelia-binding/dist/aurelia-binding.js. Trace how missing Aurelia APIs during enhance affect bootstraping, and determine the expected warning behavior from the issue's monkey patch. Done means missing APIs no longer cascade into a thrown error while the situation is still reported.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.