Why Convert2RGB() doesn't work when converting certain fill/stroke values?

Q: We get an error/assertion when processing a document's path object.
Can you help me understand how this can be avoided?

// In C++
if (path->IsFilled()) {
  ColorPt fillCol = gs->GetFillColor();
  ColorSpace cs = gs->GetFillColorSpace();
  if (cs.IsNotNull()) {
    cs.Convert2RGB(fillCol, rgb); // throws an assertion "Pattern.cpp,
line 47, expr = false"
A: The problem is most likely due to the color space.
GetFillColorSpace() most likely returns a 'pattern' color space. It is
not possible to convert pattern colorants to RGB values. To go around
this, before color converting the values, you need to make sure that
the color space is not a pattern .

if (gs->GetFillColorSpace().GetType() == ColorSpace::e_pattern) {
  // Process the pattern: ... gs->GetFillPattern()
else {
    ColorPt fillCol = gs->GetFillColor();
    cs.Convert2RGB(fillCol, rgb);

The same applies to the stroke color space.