[v2,4/4,DNI] libcamera: pipeline_handler: Break the Yaml Emitter
diff mbox series

Message ID 20241202133404.41431-5-jacopo.mondi@ideasonboard.com
State New
Headers show
Series
  • libcamera: Add support for dumping capture script in YAML
Related show

Commit Message

Jacopo Mondi Dec. 2, 2024, 1:34 p.m. UTC
Break the pipeline handler with an invalid API usage sequence
in pipeline_handler.cpp

ASSERT() for the presence of a valid parent_ reference in the YamlOutput
class hierarcy to trigger a visible error to users.

FATAL default yaml_emitter.cpp:578 assertion "parent_" failed in dict()
Backtrace: libcamera::YamlList::dict()+0xb4 (../src/libcamera/yaml_emitter.cpp:580)

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
---
 src/libcamera/pipeline_handler.cpp |  1 +
 src/libcamera/yaml_emitter.cpp     | 42 +++++-------------------------
 2 files changed, 7 insertions(+), 36 deletions(-)

Patch
diff mbox series

diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp
index e1ff6e6a5ce9..963a98e15894 100644
--- a/src/libcamera/pipeline_handler.cpp
+++ b/src/libcamera/pipeline_handler.cpp
@@ -818,6 +818,7 @@  void PipelineHandler::dumpConfiguration(const std::set<const Stream *> &streams,
 	/* \todo Dump Sensor configuration */
 
 	YamlList streamsList = configurationDict.list("streams");
+	YamlList thatsanono = configurationDict.list("shouldntbehere");
 
 	for (const auto &stream : streams) {
 		const StreamConfiguration &streamConfig = stream->configuration();
diff --git a/src/libcamera/yaml_emitter.cpp b/src/libcamera/yaml_emitter.cpp
index c0629e249c57..ed0367717e11 100644
--- a/src/libcamera/yaml_emitter.cpp
+++ b/src/libcamera/yaml_emitter.cpp
@@ -561,12 +561,7 @@  YamlList::~YamlList()
  */
 YamlList YamlList::list()
 {
-	if (!parent_) {
-		LOG(YamlEmitter, Error)
-			<< "Invalid usage of the YamlEmitter API. "
-			<< " The YAML output might not be correct.";
-		return {};
-	}
+	ASSERT(parent_);
 
 	int ret = emitSequenceStart();
 	if (ret)
@@ -580,12 +575,7 @@  YamlList YamlList::list()
  */
 YamlDict YamlList::dict()
 {
-	if (!parent_) {
-		LOG(YamlEmitter, Error)
-			<< "Invalid usage of the YamlEmitter API. "
-			<< " The YAML output might not be correct.";
-		return {};
-	}
+	ASSERT(parent_);
 
 	int ret = emitMappingStart();
 	if (ret)
@@ -600,12 +590,7 @@  YamlDict YamlList::dict()
  */
 void YamlList::scalar(std::string_view scalar)
 {
-	if (!parent_) {
-		LOG(YamlEmitter, Error)
-			<< "Invalid usage of the YamlEmitter API. "
-			<< " The YAML output might not be correct.";
-		return;
-	}
+	ASSERT(parent_);
 
 	emitScalar(scalar);
 }
@@ -652,12 +637,7 @@  YamlDict::~YamlDict()
  */
 YamlList YamlDict::list(std::string_view key)
 {
-	if (!parent_) {
-		LOG(YamlEmitter, Error)
-			<< "Invalid usage of the YamlEmitter API. "
-			<< " The YAML output might not be correct.";
-		return {};
-	}
+	ASSERT(parent_);
 
 	int ret = emitScalar(key);
 	if (ret)
@@ -677,12 +657,7 @@  YamlList YamlDict::list(std::string_view key)
  */
 YamlDict YamlDict::dict(std::string_view key)
 {
-	if (!parent_) {
-		LOG(YamlEmitter, Error)
-			<< "Invalid usage of the YamlEmitter API. "
-			<< " The YAML output might not be correct.";
-		return {};
-	}
+	ASSERT(parent_);
 
 	int ret = emitScalar(key);
 	if (ret)
@@ -702,12 +677,7 @@  YamlDict YamlDict::dict(std::string_view key)
  */
 void YamlDict::scalar(std::string_view key, std::string_view scalar)
 {
-	if (!parent_) {
-		LOG(YamlEmitter, Error)
-			<< "Invalid usage of the YamlEmitter API. "
-			<< " The YAML output might not be correct.";
-		return;
-	}
+	ASSERT(parent_);
 
 	int ret = emitScalar(key);
 	if (ret)