Skip to content

Fix/import template fix: use sentinel error for resource not-found detection in import#202

Merged
wcollins merged 4 commits into
itential:mainfrom
davhparry:fix/import-template
Jun 25, 2026
Merged

Fix/import template fix: use sentinel error for resource not-found detection in import#202
wcollins merged 4 commits into
itential:mainfrom
davhparry:fix/import-template

Conversation

@davhparry

Copy link
Copy Markdown
Contributor

Description

Fixes ipctl import template --replace failing with "item with name '...' not found" when the template does not yet exist on the server. The root cause was fragile err.Error() string comparisons in runners that checked for resource-specific strings (e.g. "template not found"), while FindByName returned a generic "item with name '...' not found" string — the two never matched.

Type of Change

  • [x ] Bug fix
  • New feature
  • Documentation
  • Refactor
  • Chore

Changes Made

Changes
pkg/resources/base.go — Added ErrNotFound sentinel and NotFoundError struct with an Is() method so errors.Is(err, ErrNotFound) works correctly
pkg/resources/FindByName — Added kind parameter so errors report the resource type (e.g. "template 'foo' not found")
pkg/resources/{accounts,device_groups,groups,jsonforms,models,projects,templates,workflows}.go — Updated all FindByName call sites to pass the resource kind
internal/runners/{templates,models,jsonforms}.go — Replaced err.Error() != "X not found" string checks with !errors.Is(err, resources.ErrNotFound)
pkg/resources/base_test.go — Unit tests for FindByName and ErrNotFound
internal/runners/templates_test.go — Integration tests covering the fixed import scenario

Testing

done
Unit tests (pkg/resources/base_test.go)
done
Integration tests (internal/runners/templates_test.go)
done
Full test suite passes (make test)
done
Manually verified import template

  • Tested Importing a new template, with and without --replace flag - Import successful
  • Tested Importing exiting template without --replace flag - Import error - already exist, use --replace flag
  • Tested Importing a non-existent template - Error - file not found

Related Issues

Closes #196

Checklist

  • [ x] Code follows the project's style guidelines
  • [ x] Self-review of code has been performed
  • [ x] Code has been commented where necessary
  • [ x] Tested with make setup or relevant profile
  • [ x] Commits follow conventional format (type: subject)
  • [ x] No secrets or credentials committed
  • [ x] Documentation has been updated accordingly
  • [ x] PR has been labeled appropriately (enhancement, bug, documentation, refactor, chore)

@davhparry davhparry force-pushed the fix/import-template branch from eeed58e to b6cb7c5 Compare June 25, 2026 08:16
…tures

Also fixes import group --replace failing when the group does not yet
exist on the server (same root cause as the template fix).

Adds the testdata fixture files that were gitignored and missing from
the branch, causing the test binary to panic on init.
@wcollins wcollins merged commit 52463d3 into itential:main Jun 25, 2026
1 check passed
@davhparry davhparry deleted the fix/import-template branch June 25, 2026 16:23
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

Successfully merging this pull request may close these issues.

bug: Unable to import template unless it already exists in the target environment

2 participants