Function validation for Integer types appears to fail when used as a timestamp in the future

I am consistently getting this error when attempting to execute my typescript function below:

{"errorCode":"INVALID_ARGUMENT","errorName":"InvalidParameterValue","errorInstanceId":"35b4668f-8456-40f1-b4dc-2c5ea714f8e0","parameters":{"parameterBaseType":"Integer","parameterId":"lockUntil","parameterValue":1753653763405}}

The function code:

@Edits(MachineExecutions)
    @OntologyEditFunction()
    public async updateMachine(
        id: string, 
        stateMachine: string, 
        state: string, 
        logs: string | undefined,
        lockOwner: string | undefined,
        lockUntil: Integer | undefined,
        ): Promise<void> {
        const solution = {
            input: '', //not relevant for this
            id: id || Uuid.random(),
            plan: '', //not relevant for this
        };

        let machine = Objects.search().machineExecutions().filter(item => item.id.exactMatch(id)).all()?.[0];

        if (!machine) {
            machine = Objects.create().machineExecutions(solution.id);
        }

        machine.machine = stateMachine;
        machine.state = state;
        machine.logs = logs;
        machine.currentState = JSON.parse(state).value;
        // set the mutex
        if (lockOwner && lockOwner.length > 0) {
            if (!lockUntil) {
                throw new Error('lockUntil must be defined when setting a lock owner!')
            }
            if (new Date(lockUntil).getTime() - Date.now() > 30 * 60 * 1000) {
                throw new Error('Invalid lock expire. The lockUntil value can not result in a date the is greater that 30 mins from now.')
            }
            machine.lockOwner = lockOwner;
            machine.lockUntil = Timestamp.fromJsDate(new Date(lockUntil))
        }
    }

My function is never called when this error is received. The execution is blocked by the functions API. The only thing I can surmise is that functions are making sure the timestamp doesn’t occur in the future. Is this what is occurring, or is something else causing this issue?

Hey @CodeStrap ,

From what I can tell in that error message you shared, you’re passing a value of 1753653763405 for an Integer parameter with name lockUntil. This value is outside the bounds that an Integer type accepts. In functions we restrict Integer values to 32-bit signed integers. (Documentation)

If you need to go higher, you could use a Long type instead. Left me know if that helps!

1 Like

Yep, I just figured that out. Would be helpful to include the ranges you restrict in the type definitions. I asked AIP this questions and it couldn’t give me an answer so I thought I would just check the type definitions. That’s probably the best place to document the ranges IMO.

It appears the Ontology does not support Long values. After updating the param to Long I get the error in the screen shot below. So I will have to pass as a string then parse int in my function. Posting here in case anyone else runs into this issue

nm, resolved by changing parameter type to Long. Just had to update the type definition of the parameter in the actions and it worked.