Comments (5)
Hey Hector, thanks a lot for tracking this down! My guess is that one of your agents is returning HTML instead of XML for some reason, as this indicates -
{ html: { head: { title: [Object] }, body: { center: [Object] } } }
I added some more error handling, and had the fetch method loop until it gets a valid looking agent response -
async fetchJsTree(type, from, count) {
const url = this.getUrl(type, from, count)
let jsTree
do {
try {
const response = await fetch(url)
const xml = await response.text() // try to parse response as xml
jsTree = convert.xml2js(xml, convertOptions) // try to convert to js tree
// make sure we have a valid agent response
if (
!jsTree.MTConnectDevices &&
!jsTree.MTConnectStreams &&
!jsTree.MTConnectError
) {
throw new Error(
'Invalid agent response - should have MTConnectDevices, MTConnectStreams, or MTConnectError.'
)
}
} catch (error) {
// error.code could be ENOTFOUND, ECONNREFUSED, EHOSTUNREACH, etc
console.error('Relay error', error)
console.log(`Relay error reading`, url)
console.log(`Relay jsTree:`)
console.dir(jsTree, { depth: 3 })
console.log(`Relay error retrying in ${waitTryAgain} ms...`)
await lib.sleep(waitTryAgain)
jsTree = null // so loop again
}
} while (!jsTree)
return jsTree
}
Hopefully that will be more robust. It's there if you'd like to give it a try - just do git pull
in the ladder99/ladder99 folder.
from ladder99.
Diving into the problem
Identification
Diving into the exact line on the data.js script it seems like the following is the key code snippet that is causing the error.
// get Header attributes for probe, current, or sample xmls.
// includes { instanceId, firstSequence, nextSequence, lastSequence, bufferSize, ... }
this.header = this.jsTree.MTConnectDevices
? this.jsTree.MTConnectDevices.Header._
: this.jsTree.MTConnectStreams.Header._
Javascript ternary operator :
condition ? exprIfTrue : exprIfFalse
This line seems to try to check the object MTConnectDevices
is not null and set the header to MTConnectDevices
if not set it to MTConnectStreams
.
I added a console.log to the script and found out that the console.log(this.jsTree.MTConnectDevices)
is outputting undefined
Seems like this is not really a header issue but a problem parsing out an endpoint.
Going Deeper
I exposed the entire this.jsTree
in the console and started looking at a pattern. After some endpoints I was able to get a successful response of the object. Note: I hid my uuid, host and port information.
Relay warning: the following devices have no alias - could add in setup.yaml.
Alias missing for device
db upsert node **{uuid}**/device: **{uuid}**/device
{
MTConnectDevices: {
_: {
'xmlns:m': 'urn:mtconnect.org:MTConnectDevices:1.5',
xmlns: 'urn:mtconnect.org:MTConnectDevices:1.5',
'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'xsi:schemaLocation': 'urn:mtconnect.org:MTConnectDevices:1.5 /schemas/MTConnectDevices_1.5.xsd'
},
Header: { _: [Object] },
Devices: { Device: [Object] }
}
}
Then shortly after another output from the relay log shows the error propping up right after a not so verbose log output.
Relay warning: the following devices have no alias - could add in setup.yaml.
Alias missing for device
db upsert node **{uuid-2}**/device: **{uuid-2}**/device
{ html: { head: { title: [Object] }, body: { center: [Object] } } }
db signal uncaughtException received - shutting down...
TypeError: Cannot read properties of undefined (reading 'Header')
at Probe.read (file:///usr/app/src/data.js:48:38)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Probe.read (file:///usr/app/src/dataProbe.js:18:5)
at async AgentReader.start (file:///usr/app/src/agentReader.js:48:7)
Summary
After noticing that the endpoints for both agents where nearly identical the issue may lie elsewhere in the endpoint collection methods. The fix I would propose is to return a handled exception instead of an unhandled exception that stops the relay service all together. I added the following to the data.js
file to handle the error :
if (this.jsTree.MTConnectDevices == undefined) {
console.log(this.jsTree)
console.log("TypeError: Cannot read properties of undefined (reading 'Header')")
return false
}
// get Header attributes for probe, current, or sample xmls.
// includes { instanceId, firstSequence, nextSequence, lastSequence, bufferSize, ... }
this.header = this.jsTree.MTConnectDevices
? this.jsTree.MTConnectDevices.Header._
: this.jsTree.MTConnectStreams.Header._
Welp... That didnt work
Caught a nice error in the face with that last idea. Looks like the best thing to do is prob a bunch of conditionals everywhere
... I ended up sticking some variation of the following in the agentReader.js do/while loops.
if ( {insert object from error} == undefined) { continue;}
from ladder99.
Awesome! I wouldnt know how the agent is sending html instead of a valid xml. I wonder if it has something to do with the agent 2.0 "agent-adapter" that we have been testing.
from ladder99.
Can you see what that agent shows in the browser?
from ladder99.
@hlopez5 has this been resolved?
from ladder99.
Related Issues (20)
- Test MQTT driver with Kepware IoT Gateway egress HOT 2
- Handle `SIGINT` and other signals to shutdown all running apps gracefully HOT 2
- Add more SQL examples how to query database HOT 2
- Create a custom driver in example setup and demonstrate it HOT 1
- Monitor disk space usage and prune dataitems when low HOT 4
- Make `l99` command installation optional HOT 1
- Create GraphQL egress endpoint HOT 1
- Add an API to manage configuration, machines and machine monitoring
- docs - bring design/*.md into main docs HOT 6
- Relay service should be an adapter.
- Allow fanuc-driver to start up with l99 stack.
- Add support for Mazak CNCs without MTConnect
- Re-design `ladder99` HOT 1
- Timezone consistency problem in Postgres ladder 99 functions or raw to public schema HOT 4
- /home/fiab/ladder99/shell/l99: line 56: /home/fiab/shell/commands/using: No such file or directory HOT 3
- With docker already installed, following the instructions to create new user, that user needs to be manually added to docker group HOT 3
- l99 shell script bad substitution HOT 3
- pgAdmin cannot connect to db HOT 5
- RTD do not seem to update from main branch. HOT 1
- How to use Meter?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ladder99.