My first time building a server side plugin and I need help. Here’s the code:
async function (properties, context) {
let dates = await properties.dateList.get(0, properties.dateList.length());
let newDate = await properties.newDate;
try {
let scalar = new Date(newDate);
let updatedDates = dates.map(date => {
let d = new Date(date);
d.setFullYear(scalar.getFullYear(), scalar.getMonth(), scalar.getDate());
return d;
});
return {
new_dates: updatedDates
};
} catch (error) {
console.error('Check your values', error);
}
}
A version of it runs client side so I don’t think it’s the function and I think I’m handling the return wrong for a server-side function. It’s supposed to return a list of dates.
Hope someone can help
I’m an ogre, here’s how I go about troubleshooting this stuff. I’m guessing it’s a type mismatch, I should probably read the docs, but – again, I’m an ogre and I don’t know how, LLMs and I are broken up.
- import
inspect
- add a return item like
output
- return the
inspect
- (optional) add a boolean like
returnedAnError
async function (properties, context) {
let dates = await properties.dateList.get(0, properties.dateList.length());
let newDate = await properties.newDate;
let { inspect } = require('node:util');
try {
let scalar = new Date(newDate);
let updatedDates = dates.map(date => {
let d = new Date(date);
d.setFullYear(scalar.getFullYear(), scalar.getMonth(), scalar.getDate());
return d;
});
return {
// new_dates: updatedDates,
output: inspect(updatedDates),
returnedAnError: false
};
} catch (error) {
console.error('Check your values', error);
return {
output: inspect(error),
returnedAnError: true
}
}
}
When you add that
let { inspect } = require('node:util');
Bubble will automatically add node:util
below as a dependency, delete it or you will have errors.
2 Likes
Thanks for the tip! I’ll give it a shot. I just need to figure out the correct return type.
Gonna peek into other plugins too.
It was such a stupid mistake. I was didn’t await properties.dateList.length()
That’s all. Holy shit that set me back 8 hours of work.
1 Like