Re: [QGIS-Developer] Retrieving error details for when a loaded layer is not valid

2021-11-27 Thread Alessandro Pasotti
Hi,

you can try with
https://qgis.org/pyqgis/3.0/core/Data/QgsDataProvider.html#qgis.core.QgsDataProvider.error



On Sat, Nov 27, 2021 at 12:11 AM Ricardo Filipe Soares Garcia da <
ricardo.garcia.si...@gmail.com> wrote:

> Hi list
>
> When loading a vector layer via Python, is there a way to get a hold of
> the error message for when the loading fails?
>
> I can check if the layer is valid or not, but I'd like to get a
> description of the error. I see the error on the QGIS log panel, so I'm
> hoping it is possible to access it from Python.
>
> ```
> # a sample of my code
> layer = QgsVectorLayer("some-bogus-url", "mylayer", "WFS")
> layer.isValid()  # this returns False
> ```
>
> Thanks in advance!
>
> --
> ___ ___ __
> Ricardo Garcia Silva
> ___
> QGIS-Developer mailing list
> QGIS-Developer@lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>


-- 
Alessandro Pasotti
QCooperative:  www.qcooperative.net
ItOpen:   www.itopen.it
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [QGIS-Developer] Retrieving error details for when a loaded layer is not valid

2021-11-26 Thread G. Allegri
Hi Ricardo,

have you tried increasing the debug level? I often raise it at 9 using
the QGIS_DEBUG env var.
>From a quick look at the source code of QgsVectorLayer two cases where the
valid flag is set to false

are when there are problems with the provider, and this is logged with
level 2.

Giovanni

Il giorno sab 27 nov 2021 alle ore 00:11 Ricardo Filipe Soares Garcia da <
ricardo.garcia.si...@gmail.com> ha scritto:

> Hi list
>
> When loading a vector layer via Python, is there a way to get a hold of
> the error message for when the loading fails?
>
> I can check if the layer is valid or not, but I'd like to get a
> description of the error. I see the error on the QGIS log panel, so I'm
> hoping it is possible to access it from Python.
>
> ```
> # a sample of my code
> layer = QgsVectorLayer("some-bogus-url", "mylayer", "WFS")
> layer.isValid()  # this returns False
> ```
>
> Thanks in advance!
>
> --
> ___ ___ __
> Ricardo Garcia Silva
> ___
> QGIS-Developer mailing list
> QGIS-Developer@lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


[QGIS-Developer] Retrieving error details for when a loaded layer is not valid

2021-11-26 Thread Ricardo Filipe Soares Garcia da
Hi list

When loading a vector layer via Python, is there a way to get a hold of the
error message for when the loading fails?

I can check if the layer is valid or not, but I'd like to get a description
of the error. I see the error on the QGIS log panel, so I'm hoping it is
possible to access it from Python.

```
# a sample of my code
layer = QgsVectorLayer("some-bogus-url", "mylayer", "WFS")
layer.isValid()  # this returns False
```

Thanks in advance!

-- 
___ ___ __
Ricardo Garcia Silva
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer