ballerina-platform / ballerina-library

The Ballerina Library
https://ballerina.io/learn/api-docs/ballerina/
Apache License 2.0
136 stars 64 forks source link

Invalid stream value created by the MySQL client #7359

Open MaryamZi opened 1 week ago

MaryamZi commented 1 week ago

Description

$title.

May apply to other clients too.

Steps to Reproduce

public isolated function getBooks() returns Book[]|sql:Error {
    stream<Book, sql:Error?> resultStream = dbClient->query(getQuery());

    if resultStream is stream<Book> {
        return from Book book in resultStream select book;
    }

    return error("Error fetching books");
}
  1. The is check should never evaluate to true, should it? But it evaluates to true.

  2. Then if there's an error (e.g., mismatched column/record names), crashes

[2024-11-13 11:08:24,871] SEVERE {b7a.log.crash} - class io.ballerina.runtime.internal.values.ErrorValue cannot be cast to class io.ballerina.runtime.internal.values.ArrayValue (io.ballerina.runtime.internal.values.ErrorValue and io.ballerina.runtime.internal.values.ArrayValue are in unnamed module of loader 'app') 
java.lang.ClassCastException: class io.ballerina.runtime.internal.values.ErrorValue cannot be cast to class io.ballerina.runtime.internal.values.ArrayValue (io.ballerina.runtime.internal.values.ErrorValue and io.ballerina.runtime.internal.values.ArrayValue are in unnamed module of loader 'app')
        at temp.getBooks(temp.bal:80)
        at temp.main(temp.bal:90)
        at $_init.$moduleExecute(.)
        at $_init.$lambda$$moduleExecute$(.)
        at io.ballerina.runtime.internal.scheduling.SchedulerItem.execute(SchedulerItem.java:54)
        at io.ballerina.runtime.internal.scheduling.Scheduler.run(Scheduler.java:320)
        at io.ballerina.runtime.internal.scheduling.Scheduler.runSafely(Scheduler.java:287)
        at java.base/java.lang.Thread.run(Thread.java:833)

Version

2201.10.0

Environment Details (with versions)

No response