Skip to content

Increase verbosity for ItemLoader, Compose and MapCompose errors #3836

@mabelvj

Description

@mabelvj

ItemLoader already provides error raising for the case of the output processor:

    def get_output_value(self, field_name):
        proc = self.get_output_processor(field_name)
        proc = wrap_loader_context(proc, self.context)
        try:
            return proc(self._values[field_name])
        except Exception as e:
            raise ValueError("Error with output processor: field=%r value=%r error='%s: %s'" % \
                (field_name, self._values[field_name], type(e)._name__, str(e)))

It could be helpful to extend this behaviour could to other ItemLoader methods:

  • _process_input_value for input processors
    def _process_input_value(self, field_name, value):
        proc = self.get_input_processor(field_name)
        proc = wrap_loader_context(proc, self.context)
        return proc(value)
  • get_value for processors that are passed as an argument to add_css, add_xpath or add_value
    def get_value(self, value, *processors, **kw):
        regex = kw.get('re', None)
        if regex:
            value = arg_to_iter(value)
            value = flatten(extract_regex(regex, x) for x in value)

        for proc in processors:
            if value is None:
                break
            proc = wrap_loader_context(proc, self.context)
            value = proc(value)
        return value

Also, Compose and MapCompose could raise errors occurring while processing the values.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions