question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to check the type of node

See original GitHub issue

I have a Yaml document with key, which can be either Yaml mapping with some configuration fields or a string as alias to some predefined configuration:

storage:
  type: fs
  location: /tmp/storage
  # etc

or

storage: default # alias to default storage

Since Yaml language is dynamic, I’m expecting to read different node types for some key, but EoYaml doesn’t support node type checks. So I need to use workarounds like:

if (yaml.string("storage") == null) {
  storage = fromConfig(yaml.mapping("storage"));
} else {
  storage = storages.get(yaml.string("storage"));
}

It would be great if I could check the type of node and convert it to string or mapping if needed. E.g. like in javax.json:

var node = yaml.node("storage");
if (node.type() == Node.STRING) {
  storage = storages.get(node.asString());
} else if (node.type() == Node.MAPPING) {
  storage = fromConfig(node.asMapping());
} else {
  // throw something
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
amihaiemilcommented, Jun 4, 2020

@g4s8 OK, let’s do it. I’ll take care of these issues in the weekend I think. Then we’ll release 5.0.0

0reactions
g4s8commented, Jun 4, 2020

@amihaiemil yes, I used old version with package private Scalar, now I can check it with instanceof, but it looks not really reliable: e.g. I may decorate Node interface somehow, then instanceof won’t work. I think it would be better to have a method like type() to check the type of node, WDYT?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I check the type of error in Node JS? - Stack Overflow
1 Answer 1 ... The thing is that I can't do a method on the string like err.code.contains(); or toLowerCase. ... code is...
Read more >
How to resolve 'node' is not recognized as an internal or ...
Open the Environment Variables option in your Control Panel. · Select the variable named Path. · Restart the command prompt again and now...
Read more >
It's impossible to check 'self' object type because of the Parse ...
Create new script; Fill it with this code: extends Node func _ready(): if (self is Spatial): pass if (self is Node2D): pass.
Read more >
Handling errors - Node-RED
These are a particular type of node.js error that can occur when a Node fails to properly handle an internal error. They cause...
Read more >
Typescript compiler can t find node with yarn - Edureka
I have @types/node installed. I'm using Yarn 2 (PnP). Seems like Typescript can't find the @types/node package? Running yarn build with the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found