Skip to content

DeleteTask should wrap error to detect IsNotExist errors #26

@maja42

Description

@maja42

It's currently not possible to check if a task actually exists.
I'd like to delete a task, and if it does not exist I want to ignore the error.
Usually this can be done by checking os.IsNotExist(err). However, taskService.DeleteTask wraps the underlying OS error with the verb %v, which effectively loses type information:

return fmt.Errorf("error deleting task %s: %v", path, getTaskSchedulerError(err))

Taskmaster should use %w instead.

I could also try something with GetRegisteredTask, but the goDoc doesn't really make sense:

// GetRegisteredTask attempts to find the specified registered task and returns a
// pointer to it if it exists. If it doesn't exist, nil will be returned in place of
// the registered task.

The return type is a struct, it can't be nil. I also can't compare it with the struct's zero-value, because the struct is not comparable due to the embedded *ole.IDispatch. But that doesn't matter, because GetRegisteredTask also returns an error - the same one as DeleteTask.

Right now, the only way I can check for this scenario is by comparing error messages - which is pretty fragile, considering that windows likes to translate error messages.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions