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

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

Open
Anthony-Mckale opened this issue Mar 29, 2018 · 6 comments

Comments

@Anthony-Mckale
Copy link

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)

@CasiOo
Copy link
Contributor

CasiOo commented Mar 29, 2018

Can't you just add a try-catch around your own code calling enhance?
I ask because it sounds like there's a bug in your code, where you're calling an Aurelia api when you shouldn't have?

@Alexander-Taran
Copy link
Contributor

Alexander-Taran commented Mar 29, 2018

@Anthony-Mckale Please provide an minimal example code when it fails for you.
How are you using it?

@jdanyow
Copy link
Contributor

jdanyow commented Mar 30, 2018

this gist is configured with the latest version of aurelia:
https://gist.run/?id=7542e061bc940cde506b

@bigopon
Copy link
Member

bigopon commented Jan 17, 2019

The error comes from ref binding, which happens when names of reference cannot be found. I think:

  1. it's a must that this fails hard & fast
  2. this error should be documented.

Would be nice if @Anthony-Mckale or some community member could help with this 😃

@magnusdanielson
Copy link

@Anthony-Mckale I use ref with enhance and it works if you register your components with .globalResources()
.globalResources( [ PLATFORM.moduleName("globals/checkaccess") ,PLATFORM.moduleName("globals/message") ]);

@Anthony-Mckale
Copy link
Author

@magnusdanielson yeah i ended up doing that for the webpack port, i'm now on a new contract doing react work, looking forward to see how aurelia next goes though

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

No branches or pull requests

6 participants