Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ ignore:
- "3rdparty/**/*" # ignore examples
- "examples/*" # ignore examples
- "tests/*" # ignore unit tests
- "scripts/generate_error_codes.py" # maintenance script, not part of the library
129 changes: 129 additions & 0 deletions .github/workflows/check_error_codes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
name: Check UR ErrorCodes version

on:
workflow_dispatch:
schedule:
- cron: '0 6 * * *' # Every night at 06:00 UTC

jobs:
check_error_codes:
name: Check UR ErrorCodes JSON version
runs-on: ubuntu-latest
permissions:
contents: write # push update branch
issues: write # open notification issue
pull-requests: write # open PR with the regenerated header

steps:
- uses: actions/checkout@v7

- name: Check error codes version
id: check
# continue-on-error so subsequent steps can still run and open a PR/issue
continue-on-error: true
run: |
python3 scripts/generate_error_codes.py \
--check \
--header include/ur_client_library/ur/error_code_texts.h

- name: Extract versions
if: steps.check.outcome == 'failure'
id: versions
run: |
COMMITTED=$(python3 -c "
import re
m = re.search(r'ERROR_CODE_JSON_VERSION\s*=\s*\"([^\"]+)\"',
open('include/ur_client_library/ur/error_code_texts.h').read())
print(m.group(1) if m else 'unknown')
")
UPSTREAM=$(python3 -c "
import urllib.request, json
data = json.loads(urllib.request.urlopen(
'https://www.universal-robots.com/manuals/EN/PDF/Shared/ErrorCodes/ErrorCodes.json'
).read())
print(data.get('version', 'unknown'))
")
# Validate both versions match N.N.N before using them in branch
# names, PR titles, and commit messages. An unexpected format
# (e.g. containing '/', '"', or newlines) would otherwise allow
# injection into those fields.
VERSION_RE='^[0-9]+\.[0-9]+\.[0-9]+$'
if ! echo "$COMMITTED" | grep -qE "$VERSION_RE"; then
echo "ERROR: committed version '$COMMITTED' does not match expected N.N.N format" >&2
exit 1
fi
if ! echo "$UPSTREAM" | grep -qE "$VERSION_RE"; then
echo "ERROR: upstream version '$UPSTREAM' does not match expected N.N.N format" >&2
exit 1
fi

echo "committed=$COMMITTED" >> "$GITHUB_OUTPUT"
echo "upstream=$UPSTREAM" >> "$GITHUB_OUTPUT"

- name: Ensure label exists
if: steps.check.outcome == 'failure' && steps.versions.outcome == 'success'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh label create "error-codes-outdated" \
--description "Upstream UR ErrorCodes JSON has a newer version than the committed header" \
--color "e4e669" \
--force

- name: Regenerate header and open PR
if: steps.check.outcome == 'failure' && steps.versions.outcome == 'success'
id: pr
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMITTED: ${{ steps.versions.outputs.committed }}
UPSTREAM: ${{ steps.versions.outputs.upstream }}
run: |
BRANCH="auto/update-error-codes-v${UPSTREAM}"

# Skip if a PR for exactly this branch is already open
OPEN_PR=$(gh pr list \
--label "error-codes-outdated" \
--state open \
--json headRefName \
--jq "[.[] | select(.headRefName == \"$BRANCH\")] | length")

if [ "$OPEN_PR" -gt 0 ]; then
echo "PR for branch $BRANCH already open — skipping."
echo "pr_url=" >> "$GITHUB_OUTPUT"
else
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout -b "$BRANCH"
Comment thread
urfeex marked this conversation as resolved.

python3 scripts/generate_error_codes.py \
--overlay scripts/error_code_overrides.json \
--output include/ur_client_library/ur/error_code_texts.h

git add include/ur_client_library/ur/error_code_texts.h
git commit -m "chore: update error_code_texts.h to UR ErrorCodes JSON v${UPSTREAM}"
git push origin "$BRANCH"
Comment thread
urfeex marked this conversation as resolved.

PR_URL=$(gh pr create \
--title "chore: update error_code_texts.h to UR ErrorCodes JSON v${UPSTREAM}" \
--label "error-codes-outdated" \
--base "${{ github.event.repository.default_branch }}" \
--head "$BRANCH" \
--body "The upstream UR ErrorCodes JSON has been updated. This PR regenerates \`error_code_texts.h\` automatically.

| | Version |
|---|---|
| Previous header (\`ERROR_CODE_JSON_VERSION\`) | \`${COMMITTED}\` |
| Upstream JSON | \`${UPSTREAM}\` |

**Workflow run:** ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}

> [!NOTE]
> Only \`include/ur_client_library/ur/error_code_texts.h\` is updated here.
> If you have pending entries in \`scripts/error_code_overrides.json\`, verify
> they are still correct against the new JSON before merging.")

echo "pr_url=$PR_URL" >> "$GITHUB_OUTPUT"
fi
- name: Fail if version mismatch
if: steps.check.outcome == 'failure'
run: exit 1
32 changes: 32 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ add_library(urcl
src/primary/primary_client.cpp
src/primary/robot_message.cpp
src/primary/robot_message/error_code_message.cpp
src/ur/error_code_overrides.cpp
Comment thread
urfeex marked this conversation as resolved.
src/primary/robot_message/key_message.cpp
src/primary/robot_message/runtime_exception_message.cpp
src/primary/robot_message/text_message.cpp
Expand Down Expand Up @@ -131,6 +132,37 @@ if(CMAKE_COMPILE_WARNING_AS_ERROR)
endif()
endif()

##
## Error code text generation / version check targets
##
find_package(Python3 COMPONENTS Interpreter)
if(Python3_FOUND)
set(_error_codes_header
"${CMAKE_CURRENT_SOURCE_DIR}/include/ur_client_library/ur/error_code_texts.h")
set(_error_codes_overlay
"${CMAKE_CURRENT_SOURCE_DIR}/scripts/error_code_overrides.json")
set(_error_codes_script
"${CMAKE_CURRENT_SOURCE_DIR}/scripts/generate_error_codes.py")

add_custom_target(generate_error_codes
COMMAND ${Python3_EXECUTABLE} ${_error_codes_script}
--overlay ${_error_codes_overlay}
--output ${_error_codes_header}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Regenerating error_code_texts.h from upstream UR ErrorCodes JSON"
VERBATIM
)

add_custom_target(check_error_codes
COMMAND ${Python3_EXECUTABLE} ${_error_codes_script}
--check
--header ${_error_codes_header}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Checking error_code_texts.h version against upstream UR ErrorCodes JSON"
VERBATIM
)
endif()

##
## Build testing if enabled by option
##
Expand Down
10 changes: 5 additions & 5 deletions include/ur_client_library/primary/primary_consumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class PrimaryConsumer : public AbstractPrimaryConsumer
code.timestamp = pkg.timestamp_;
code.to_string = pkg.toString();

const auto log_contents = "Logging an ErrorCodeMessage from the UR Controller Box: " + pkg.toString();
const auto log_contents = pkg.toString();
Comment thread
urfeex marked this conversation as resolved.

switch (code.report_level)
{
Expand All @@ -143,18 +143,18 @@ class PrimaryConsumer : public AbstractPrimaryConsumer
case ReportLevel::DEVL_VIOLATION:
case ReportLevel::DEVL_FAULT:
case ReportLevel::DEVL_CRITICAL_FAULT:
URCL_LOG_DEBUG(log_contents.c_str());
URCL_LOG_DEBUG("%s", log_contents.c_str());
break;
case ReportLevel::INFO:
URCL_LOG_INFO(log_contents.c_str());
URCL_LOG_INFO("%s", log_contents.c_str());
break;
case ReportLevel::WARNING:
URCL_LOG_WARN(log_contents.c_str());
URCL_LOG_WARN("%s", log_contents.c_str());
break;
case ReportLevel::VIOLATION:
case ReportLevel::FAULT:
case ReportLevel::CRITICAL_FAULT:
URCL_LOG_ERROR(log_contents.c_str());
URCL_LOG_ERROR("%s", log_contents.c_str());
break;
}

Expand Down
72 changes: 72 additions & 0 deletions include/ur_client_library/ur/error_code_overrides.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-

// -- BEGIN LICENSE BLOCK ----------------------------------------------
// Copyright 2026 Universal Robots A/S
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
// -- END LICENSE BLOCK ------------------------------------------------

//----------------------------------------------------------------------
/*!\file
*
* Declaration of the dynamic error-code text override hook.
*
* Edit src/ur/error_code_overrides.cpp to add
* runtime-computed descriptions for specific error codes. That file
* is intentionally NOT touched by the code-generation script.
*
*/
//----------------------------------------------------------------------

#pragma once

#include <cstdint>
#include <optional>
#include <string>

namespace urcl
{
namespace primary_interface
{
/*!
* \brief Optional dynamic override for an error code text.
*
* Called by ErrorCodeMessage::toString() before the static lookup table.
* Return a non-empty optional to supply a custom description; return
* std::nullopt to fall through to the generated table.
*
* Implement additional cases in
* src/ur/error_code_overrides.cpp.
*
* \param code The error code (message_code_)
* \param arg The error argument (message_argument_)
* \returns A human-readable string, or std::nullopt
*/
std::optional<std::string> getErrorCodeTextOverride(int32_t code, int32_t arg);

} // namespace primary_interface
} // namespace urcl
Loading
Loading