Custom block to insert steps inside

Hello,

Could I create a Server Connect extension/module like the Try/Catch? I’ve checked the Try/Catch code but I don’t know how to make the hjson.

I see some pretty funny possibilities with modules that allow steps inside. Like building a Cache block or throwing everything into a Queue for later processing.

Now, a question for the Wappler team: Method trycatch is executed, with the argument “options” being an object containing “try” and “catch” (see picture on right)

Line 180, trycatch calls exec with argument options.try, which is an object containing “steps” (see picture on right)

Line 193, there’s an if (options.exec […]), but argument (options) only has “steps”! There’s no “exec”! It would always fail, what am I missing?

// core.js
trycatch: async function(options) {
        try {
            await this.exec(options.try, true);
        } catch (error) {
            this.scope.set('$_ERROR', error.message || error);
            this.error = false;
            if (options.catch) {
                await this.exec(options.catch, true);
            }
        }
    },

exec: async function(options) {
        var data = {};

        if (options.exec && fs.existsSync(`app/modules/lib/${options.exec}.json`)) {
            let parentData = this.data;
            this.data = {};
            this.scope = this.scope.create({ $_PARAM: this.parse(options.params) });
            await this.exec(await fs.readJSON(`app/modules/lib/${options.exec}.json`), true);
            data = this.data;
            this.scope = this.scope.parent;
            this.data = parentData;
        } else {
            throw new Error(`There is no action called '${options.exec}' found in the library.`);
        }

        return data;
    },
1 Like

Yes, but no :smiley:

There is a template object that can be defined in the hjson file, but right now I believe it only works for some core modules.

@Apple I revisited this because I think I didn’t understand your ask.

Try with this in the hjson:

{ name: 'block', optionName: 'block', title: 'block', type: 'steps', required: true },

image

These undocumented features mean that they are subject to changes by the team and breaking. Take that into consideration.

1 Like

This is the Hjson for try/cache block, so you can do something similar:

{
		module : 'core',
		action : 'trycatch',
		groupTitle : 'Core Actions',
		groupIcon : 'fas fa-lg fa-cube comp-flows',
		title : 'Try/Catch',
		icon : 'fas fa-lg fa-check-circle comp-flows',
		state : 'opened',
		noNamespace: true,
		properties : [
			{
				group: 'Try Properties',
			 	variables: [
					{	name: 'try', optionName: 'try', title: 'try',	type: 'steps', required: true	},
					{	name: 'catch', optionName: 'catch', title: 'catch',	type: 'steps'	}
				]
			}
		]
	};

Can you share the HJSON for Repeat, Parallel and Group too?

Actually now we have a new ‘group’ action that will allow you to group together multiple action steps.

It is also useful to created nested data output. Just make sure you give it a name.