From a0428d90d60264bf21f70037e9851a8178edebfb Mon Sep 17 00:00:00 2001 From: teatov Date: Sun, 3 Aug 2025 23:33:35 +1000 Subject: [PATCH] replace `printerr` with `push_error` and `push_warning` --- scripts/globals/layout_config.gd | 20 ++++++++++---------- scripts/layouts/layout_custom.gd | 12 ++++++------ scripts/layouts/parser_kle.gd | 2 +- scripts/layouts/parser_qmk.gd | 14 +++++++------- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/scripts/globals/layout_config.gd b/scripts/globals/layout_config.gd index 6c367df..e19d130 100644 --- a/scripts/globals/layout_config.gd +++ b/scripts/globals/layout_config.gd @@ -53,7 +53,7 @@ func swap_layout(layout_name: String) -> void: _set_layout(layouts[layout_name]) layout_swapped.emit(current_layout) else: - printerr("layout '%s' not found" % layout_name) + push_error("layout '%s' not found" % layout_name) func _set_defaults() -> void: @@ -76,7 +76,7 @@ func _load_config() -> Error: return FAILED if err != OK: - printerr("failed to load layout config file: '%s'" % err) + push_error("failed to load layout config file: '%s'" % err) print() return FAILED @@ -84,12 +84,12 @@ func _load_config() -> Error: if _config.has_section_key(SECTION_INFO, PARAM_NAME): layout_name = _config.get_value(SECTION_INFO, PARAM_NAME, "") as String else: - printerr("layout config is missing '%s/%s'" % [SECTION_INFO, PARAM_NAME]) + push_error("layout config is missing '%s/%s'" % [SECTION_INFO, PARAM_NAME]) if layout_name != "" and layouts.has(layout_name): _set_layout(layouts[layout_name]) else: - printerr("layout '%s' not found" % layout_name) + push_error("layout '%s' not found" % layout_name) _set_defaults() for row: Array[KeyProps] in layout_rows: @@ -126,7 +126,7 @@ func _save_config() -> Error: var err := _config.save(CONFIG_PATH) if err != OK: - printerr("failed to save config file: '%s'" % err) + push_error("failed to save config file: '%s'" % err) return err return OK @@ -136,22 +136,22 @@ func _load_custom_layouts(path: String) -> void: if not DirAccess.dir_exists_absolute(path): var dir_err := DirAccess.make_dir_absolute(path) if dir_err != OK: - printerr("error creating directory '%s': %s" % [path, dir_err]) + push_error("error creating directory '%s': %s" % [path, dir_err]) print() return var file_err := DirAccess.copy_absolute( CUSTOM_LAYOUTS_README, path.path_join(CUSTOM_LAYOUTS_README.get_file()) ) if file_err != OK: - printerr("error copying file '%s': %s" % [CUSTOM_LAYOUTS_README, file_err]) + push_error("error copying file '%s': %s" % [CUSTOM_LAYOUTS_README, file_err]) var dir := DirAccess.open(path) if not dir: var err := DirAccess.get_open_error() if err == ERR_FILE_NOT_FOUND: - printerr("directory not found '%s'" % path) + push_error("directory not found '%s'" % path) else: - printerr("error opening directory '%s': %s" % [path, err]) + push_error("error opening directory '%s': %s" % [path, err]) print() return @@ -167,7 +167,7 @@ func _load_custom_layouts(path: String) -> void: if layout.failed: continue if layouts.has(layout.get_name()): - printerr( + push_warning( ( "layout '%s' already exists and will be replaced by the new one" % [layout.get_name()] diff --git a/scripts/layouts/layout_custom.gd b/scripts/layouts/layout_custom.gd index fea5add..0591272 100644 --- a/scripts/layouts/layout_custom.gd +++ b/scripts/layouts/layout_custom.gd @@ -15,14 +15,14 @@ func _init(path: String) -> void: var data: Variant = _load_json_file(path) if not data: failed = true - printerr("%s: COULD NOT PARSE CUSTOM LAYOUT JSON" % _file_name) + push_error("%s: COULD NOT PARSE CUSTOM LAYOUT JSON" % _file_name) print() return var layout_rows := _deserialize(data, _file_name) if not layout_rows: failed = true - printerr("%s: COULD NOT DESERIALIZE CUSTOM LAYOUT" % _file_name) + push_error("%s: COULD NOT DESERIALIZE CUSTOM LAYOUT" % _file_name) print() return @@ -44,16 +44,16 @@ func _load_json_file(path: String) -> Variant: if not file: var file_err := FileAccess.get_open_error() if file_err == ERR_FILE_NOT_FOUND: - printerr("%s: file not found" % _file_name) + push_error("%s: file not found" % _file_name) else: - printerr("%s: error opening file: %s" % [_file_name, file_err]) + push_error("%s: error opening file: %s" % [_file_name, file_err]) return [] var content := file.get_as_text() var json := JSON.new() var err := json.parse(content) if err != OK: - printerr( + push_error( ( "%s: json parse error at line %s: %s" % [_file_name, json.get_error_line(), json.get_error_message()] @@ -73,7 +73,7 @@ func _deserialize(data: Variant, path: String) -> Array[Array]: elif data is Dictionary: parser = ParserQMK.new(data as Dictionary, path) else: - printerr( + push_error( "%s: top-level json item is neither an array nor a dictionary" % _file_name ) return [] diff --git a/scripts/layouts/parser_kle.gd b/scripts/layouts/parser_kle.gd index c8fde1f..71f7d63 100644 --- a/scripts/layouts/parser_kle.gd +++ b/scripts/layouts/parser_kle.gd @@ -259,7 +259,7 @@ func _get_keycode_from_legend( break if keycode == KEY_NONE: - printerr("%s: could not recognize key label %s" % [_file_name, str(legend)]) + push_warning("%s: could not recognize key label %s" % [_file_name, str(legend)]) _has_errors = true return keycode diff --git a/scripts/layouts/parser_qmk.gd b/scripts/layouts/parser_qmk.gd index cd90b20..4c65707 100644 --- a/scripts/layouts/parser_qmk.gd +++ b/scripts/layouts/parser_qmk.gd @@ -182,7 +182,7 @@ func _init(data: Dictionary, file_name: String) -> void: or data[LAYOUTS] is not Dictionary or (data[LAYOUTS] as Dictionary).size() == 0 ): - printerr("%s: '%s' does not exist" % [_file_name, LAYOUTS]) + push_error("%s: '%s' is missing" % [_file_name, LAYOUTS]) _has_errors = true return @@ -193,8 +193,8 @@ func _init(data: Dictionary, file_name: String) -> void: or not (data[LAYOUTS][layout_name] as Dictionary).has(LAYOUT) or data[LAYOUTS][layout_name][LAYOUT] is not Array ): - printerr( - "%s: '%s.%s.%s' does not exist" % [_file_name, LAYOUTS, layout_name, LAYOUT] + push_error( + "%s: '%s.%s.%s' is missing" % [_file_name, LAYOUTS, layout_name, LAYOUT] ) _has_errors = true return @@ -322,9 +322,9 @@ func _get_keymap_keys(data_keys: Array, json_file_name: String) -> Error: if not file: var file_err := FileAccess.get_open_error() if file_err == ERR_FILE_NOT_FOUND: - printerr("%s: file '%s' not found" % [_file_name, c_file_name]) + push_error("%s: file '%s' not found" % [_file_name, c_file_name]) else: - printerr( + push_error( "%s: error opening file '%s': %s" % [_file_name, c_file_name, file_err] ) return FAILED @@ -341,7 +341,7 @@ func _get_keymap_keys(data_keys: Array, json_file_name: String) -> Error: var layout_match := layout_regex.search(content) if not layout_match: - printerr( + push_error( "%s: no layout keymap definitions found in '%s'" % [_file_name, c_file_name] ) return FAILED @@ -375,7 +375,7 @@ func _get_keycode_from_keymap_key(keymap_key_prefixed: String) -> Key: keycode = KEYCODE_MODIFIER_RIGHT_MAP[keymap_key] if keycode == KEY_NONE: - printerr( + push_warning( "%s: could not recognize key label '%s'" % [_file_name, keymap_key_prefixed] ) _has_errors = true