From 19d6cc3d8b2489b6b652f5b1af6babe9cc26b6df Mon Sep 17 00:00:00 2001 From: Karstein Phobic Nyvold Kvistad Date: Tue, 28 Apr 2026 20:51:32 +0200 Subject: [PATCH] fix(create_folder): dump dir(parent) on total-miss to diagnose unknown SPs Empirical failure: TypeError create_folder() got an unexpected keyword argument 'name' (original v1). Root cause: kwarg 'name=' rejected by SP21+; positional foldername is the canonical signature. Fix: positional call (already landed in e0fea90); this commit adds a dir(parent) dump on total-miss for forward-compat diagnostics. Docs: https://content.helpme-codesys.com/en/ScriptingEngine/ScriptObject.html Note: the core fix (positional call + multi-strategy fallback) was already landed in commit e0fea90. This commit only adds the dir(parent_object) dump to the final error path -- per the bug doc's "dump dir(parent) on total miss" recommendation -- so an SP that breaks all 5 strategies surfaces the real API surface in the failure message instead of leaving the next investigator blind. ### Manual smoke test 1. mcp__codesys__create_folder against any normally-functioning project should still succeed (Strategy 1 wins -- the dir() dump only triggers when ALL strategies fail). 2. To exercise the new dir() path, run create_folder against a project whose Application has been deleted (parent_object resolves to a container without create_folder/create_object/add): expect SCRIPT_ERROR ending with "parent api: ". --- src/scripts/create_folder.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/scripts/create_folder.py b/src/scripts/create_folder.py index 3e71cac..f6e87e3 100644 --- a/src/scripts/create_folder.py +++ b/src/scripts/create_folder.py @@ -149,9 +149,19 @@ try: print("WARN: parent.add(types.IecFolder) raised: %s" % e) if new_folder is None: + # Total miss -- dump dir(parent) to surface what API surface this + # SP actually exposes, so the next iteration can target it. Helps + # OPEN-BUGS-CROSS-REFERENCE Bug 1 diagnosis on unexpected SPs. + try: + api_attrs = sorted([a for a in dir(parent_object) if not a.startswith('_')]) + api_dump = ', '.join(api_attrs) + except Exception as de: + api_dump = '' % de raise TypeError( - "Parent object '%s' of type %s -- folder '%s' could not be created or located after trying %s." % ( - parent_name, type(parent_object).__name__, FOLDER_NAME, ', '.join(strategies_tried) or '')) + "Parent object '%s' of type %s -- folder '%s' could not be created or located after trying %s. parent api: %s" % ( + parent_name, type(parent_object).__name__, FOLDER_NAME, + ', '.join(strategies_tried) or '', + api_dump)) if new_folder: new_folder_name = getattr(new_folder, 'get_name', lambda: FOLDER_NAME)()