Skip to content

Conversation

@dido18
Copy link
Contributor

@dido18 dido18 commented Nov 12, 2025

Motivation

When a brick with required variables is added to an app created from scratch the operation fails.

This is because the BE returns an error if the required variables are not set when the PUT /v1/apps/{appID}/bricks/{brickID} is called. For example, the brick arduino:arduino_cloud has the ARDUINO_DEVICE_ID and ARDUINO_SECRET required.

Additionally, the issue does not occur when an app with a brick already added is cloned.
This is because when an app is cloned the backend does not check if the required variables are missing.

Change description

  1. Allow missing required variables when a brick is added to an app. A Warning is printed.
  2. add tests for the (PATCH /v1/apps/{appID}/bricks/{brickID}) endpoint
  3. Validate the required variable of a brick when an app is started or restarted. For each brick in the ' app.yaml`, the following validation is performed:
    1. invalid if a required variable is omitted
    2. invalid if the brick ID is not found in the bricks index
    3. log a warning if a variable does not exist in the brick definition

Additional notes

  • Currently, the only brick that has required variables is arduino_cloud. Starting an app that uses the arduino_cloud without specifying the required variables ARDUINO_SECRET and ARDUINO_DEVICE_ID will raise an error.

Examples of errors

Example:
Given the following app-yaml, where the required ARDUINO_SECRET variable of arduino:arduino_cloud is missing:

name: hello
description: ""
ports: []
bricks:
- arduino:arduino_cloud: 
  variables:
      ARDUINO_DEVICE_ID: ""
icon: 😀

When an app is started

  • from arduino-app-cli
$ arduino-app-cli app start user:ciao
[ERROR] Variable "Arduino_secret" Is Required By Brick "Arduino:arduino_cloud"
  • from the FE:
variable "ARDUINO_SECRET" is required by brick "arduino:arduino_cloud" variable "ARDUINO_DEVICE_ID" is required by brick "arduino:arduino_cloud"

When an app is restarted

arduino@merola:/$ arduino-app-cli app restart user:ciao
[ERROR] Variable "Arduino_device_id" Is Required By Brick "Arduino:arduino_cloud"
Variable "Arduino_secret" Is Required By Brick "Arduino:arduino_cloud"
arduino@merola:/$

Additional Notes

Reviewer checklist

  • PR addresses a single concern.
  • PR title and description are properly filled.
  • Changes will be merged in main.
  • Changes are covered by tests.
  • Logging is meaningful in case of troubleshooting.

@dido18 dido18 changed the title fix(api): add brick allow empry required variable fix(api): allow empty required variable when a brick id added Nov 12, 2025
@dido18 dido18 changed the title fix(api): allow empty required variable when a brick id added fix(api): allow empty required variable when a brick is added Nov 12, 2025
@dido18 dido18 changed the title fix(api): allow empty required variable when a brick is added fix(api): allow missing required variable when a brick is added Nov 12, 2025
@dido18 dido18 marked this pull request as ready for review November 12, 2025 17:24
@per1234 per1234 added the bug Something isn't working label Nov 12, 2025
@dido18 dido18 requested a review from a team November 14, 2025 16:14
@dido18 dido18 changed the title fix(api): allow missing required variable when a brick is added fix(api): allow missing required variable when a brick is added + app validation Nov 14, 2025
@dido18 dido18 marked this pull request as draft November 17, 2025 08:49
@dido18
Copy link
Contributor Author

dido18 commented Nov 17, 2025

Running this script to test the validation of the example 0.5.0

set -o pipefail

base_path="/home/arduino/.local/share/arduino-app-cli/examples"

for dir in $(find "$base_path" -type d -name "sketch" ! -path "*/.cache/*"); do
    parent=$(basename "$(dirname "$dir")")
	echo "\033[32mTesting example: $parent\033[0m"

    if arduino-app-cli app start "examples:$parent"; then
		echo "\033[32mApp started successfully: examples:$parent\033[0m"
	else
		echo "\033[31mFailed to start app: examples:$parent\033[0m"
	fi
	arduino-app-cli app stop "examples:$parent"
	echo ""
done

@dido18 dido18 marked this pull request as ready for review November 17, 2025 10:18
@mirkoCrobu
Copy link
Contributor

mirkoCrobu commented Nov 17, 2025

When a brick is added to an app: DO NOT raise an error, BUT log a Warning and set the required variable as an empty string.

Doesn't this approach risk assigning a non-compatible value for a mandatory variable? What happens in this case?

The result is that the required variable is set as an empty string in the app.yaml (see the tests "do not fail if a mandatory variable is not present").

@dido18 dido18 requested a review from lucarin91 November 20, 2025 09:44
@dido18 dido18 requested a review from lucarin91 November 21, 2025 09:55
@dido18 dido18 merged commit cd29de0 into main Nov 21, 2025
6 checks passed
@dido18 dido18 deleted the fix-add-brick branch November 21, 2025 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: it is not possible to add the Arduino Cloud brick into a newly created app

4 participants