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

default values are not used / Example Graph from getting started tutorial #737

Open
aheissenberger opened this issue May 14, 2021 · 0 comments

Comments

@aheissenberger
Copy link

aheissenberger commented May 14, 2021

Example:
when running the example app from the get get started tutorial the encoding is not set to 'utf-8' and output ist a buffer and not the text of package.json:

noflo-test % ./node_modules/.bin/noflo-nodejs --graph src/graphs/ShowConents.fbp --batch --debug
Debugger attached.
ShowConents started on Fri May 14 2021 03:07:51 GMT+0200 (Mitteleuropäische Sommerzeit)
DATA -> IN Read() DATA
DATA -> ENCODING Read() DATA
Read() OUT -> IN Display() openBracket package.json
Read() OUT -> IN Display() DATA
<Buffer 7b 0a 20 20 22 6e 61 6d 65 22 3a 20 22 6e 6f 66 6c 6f 2d 74 65 73 74 22 2c 0a 20 20 22 76 65 72 73 69 6f 6e 22 3a 20 22 31 2e 30 2e 30 22 2c 0a 20 20 ... 200 more bytes>
Read() OUT -> IN Display() closeBracket package.json
ShowConents ended on Fri May 14 2021 03:08:41 GMT+0200 (Mitteleuropäische Sommerzeit) (uptime 50.001 seconds)

This is the definition in node_modules/noflo-filesystem/components/ReadFile.js:

c.inPorts.add('encoding', {
    datatype: 'string',
    description: 'File encoding',
    default: 'utf-8',
    control: true,
  });

This is the implementation node_modules/noflo/lib/InPort.js:

// Assign a delegate for retrieving data should this inPort
    attachSocket(socket, localId = null) {
        // have a default value.
        if (this.hasDefault()) {
            socket.setDataDelegate(() => this.options.default);
        }
        socket.on('connect', () => this.handleSocketEvent('connect', socket, localId));
        socket.on('begingroup', (group) => this.handleSocketEvent('begingroup', group, localId));
        socket.on('data', (data) => {
            this.validateData(data);
            return this.handleSocketEvent('data', data, localId);
        });
        socket.on('endgroup', (group) => this.handleSocketEvent('endgroup', group, localId));
        socket.on('disconnect', () => this.handleSocketEvent('disconnect', socket, localId));
        socket.on('ip', (ip) => this.handleIP(ip, localId));
    }

I was able to debug the problem - socket.setDataDelegate(() => this.options.default); was called on InPort encoding.
her in node_modules/noflo/lib/InternalSocket.js emits the default data in payload:

handleSocketEvent(event, payload, autoConnect = true) {
  ...
  this.emitEvent(event, payload);
}

node_modules/noflo/lib/InPort.js func handleSocketEvent emits the payload

in node_modules/noflo/lib/BaseNetwork.js func sendDefaults() I found this note which could explain the problem:

// Don't send defaults if more than one socket is present on the port.
            // This case should only happen when a subgraph is created as a component
            // as its network is instantiated and its inputs are serialized before
            // a socket is attached from the "parent" graph.

I was able to get the example working by adding an Input in the graph file:

broken:

# In the graph we first need to define the nodes and the connections between them
Read(filesystem/ReadFile) OUT -> IN Display(core/Output)

# Start off the graph by sending a filename to the file reader
'package.json' -> IN Read

working - only if 'utf-8' -> encoding Read is defined before IN Read

# In the graph we first need to define the nodes and the connections between them
Read(filesystem/ReadFile) OUT -> IN Display(core/Output)

# Start off the graph by sending a filename to the file reader
'utf-8' -> encoding Read
'package.json' -> IN Read
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant