Repository: astropy/astroquery

Issue:
BUG: XMatch two Vizier catalogs then no col refs should be added
When matching two catalogs from Vizier no reference columns should be specified, currently we're wrongly raise an exception:

```
In [17]: from astropy import units as u
    ...: from astroquery.xmatch import XMatch
    ...: table = XMatch.query_async(cat1='vizier:J/A+A/331/81/table2', cat2='vizier:IV/34/epic', max_distance=5 * u.arcsec)
    ...: 
    ...: 
    ...: 
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-17-6263e825bbc7> in <module>()
      1 from astropy import units as u
      2 from astroquery.xmatch import XMatch
----> 3 table = XMatch.query_async(cat1='vizier:J/A+A/331/81/table2', cat2='vizier:IV/34/epic', max_distance=5 * u.arcsec)
      4 

~/munka/devel/astroquery/astroquery/xmatch/core.py in query_async(self, cat1, cat2, max_distance, colRA1, colDec1, colRA2, colDec2, cache, get_query_payload)
     83         kwargs = {}
     84 
---> 85         self._prepare_sending_table(1, payload, kwargs, cat1, colRA1, colDec1)
     86         self._prepare_sending_table(2, payload, kwargs, cat2, colRA2, colDec2)
     87 

~/munka/devel/astroquery/astroquery/xmatch/core.py in _prepare_sending_table(self, i, payload, kwargs, cat, colRA, colDec)
    115         if not self.is_table_available(cat):
    116             if ((colRA is None) or (colDec is None)):
--> 117                 raise ValueError('Specify the name of the RA/Dec columns in' +
    118                                  ' the input table.')
    119             # if `cat1` is not a VizieR table,

ValueError: Specify the name of the RA/Dec columns in the input table.
```



Discussion:
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/astropy/astroquery/pull/3168?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=astropy) Report
Attention: Patch coverage is `0%` with `1 line` in your changes missing coverage. Please review.
> Project coverage is 67.67%. Comparing base [(`fbf55b0`)](https://app.codecov.io/gh/astropy/astroquery/commit/fbf55b0f2c0618db3166f176fb91027d8e30fab8?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=astropy) to head [(`fcbaff0`)](https://app.codecov.io/gh/astropy/astroquery/commit/fcbaff0a819509e73148941e2c5a453f624e456b?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=astropy).
> Report is 4 commits behind head on main.

| [Files with missing lines](https://app.codecov.io/gh/astropy/astroquery/pull/3168?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=astropy) | Patch % | Lines |
|---|---|---|
| [astroquery/xmatch/core.py](https://app.codecov.io/gh/astropy/astroquery/pull/3168?src=pr&el=tree&filepath=astroquery%2Fxmatch%2Fcore.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=astropy#diff-YXN0cm9xdWVyeS94bWF0Y2gvY29yZS5weQ==) | 0.00% | [1 Missing :warning: ](https://app.codecov.io/gh/astropy/astroquery/pull/3168?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=astropy) |

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main    #3168      +/-   ##
==========================================
+ Coverage   67.49%   67.67%   +0.18%     
==========================================
  Files         232      229       -3     
  Lines       18446    18365      -81     
==========================================
- Hits        12450    12429      -21     
+ Misses       5996     5936      -60     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/astropy/astroquery/pull/3168?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=astropy).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=astropy).


Patch:
diff --git a/CHANGES.rst b/CHANGES.rst
index 80dfdf76..390c5ab8 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -286,6 +286,9 @@ xmatch
 - Fix xmatch query for two local tables. The second table was written over the first one,
   resulting in a confusing "missing cat1" error. [#3116]
 
+- Make the error message clearer about VizieR tables not available for
+  crossmatching [#3168]
+
 
 0.4.7 (2024-03-08)
 ==================
diff --git a/astroquery/xmatch/core.py b/astroquery/xmatch/core.py
index 57cc9549..051f07a2 100644
--- a/astroquery/xmatch/core.py
+++ b/astroquery/xmatch/core.py
@@ -146,7 +146,12 @@ class XMatchClass(BaseQuery):
 
         if not self.is_table_available(cat):
             if ((colRA is None) or (colDec is None)):
-                raise ValueError('Specify the name of the RA/Dec columns in the input table.')
+                raise ValueError(
+                    f"'{cat}' is not available on the XMatch server. If you are "
+                    "using a VizieR table name, note that only tables with "
+                    "coordinates are available on the XMatch server. If you are "
+                    f"using a local table, the arguments 'colRA{cat_index}' and "
+                    f"'colDec{cat_index}' must be provided.")
             # if `cat1` is not a VizieR table,
             # it is assumed it's either a URL or an uploaded table
             payload['colRA{0}'.format(cat_index)] = colRA


Test patch:
diff --git a/astroquery/xmatch/tests/test_xmatch.py b/astroquery/xmatch/tests/test_xmatch.py
index d1c9899a..8c303516 100644
--- a/astroquery/xmatch/tests/test_xmatch.py
+++ b/astroquery/xmatch/tests/test_xmatch.py
@@ -1,5 +1,6 @@
 # Licensed under a 3-clause BSD style license - see LICENSE.rst
 from pathlib import Path
+import re
 
 import requests
 import pytest
@@ -114,3 +115,13 @@ def test_two_local_tables():
                              max_distance=1 * arcsec,
                              get_query_payload=True)
     assert 'cat1' in payload[1]["files"] and 'cat2' in payload[1]["files"]
+
+
+def test_table_not_available(monkeypatch):
+    xm = XMatch()
+    monkeypatch.setattr(xm, '_request', request_mockreturn)
+    cat1 = "vizier:J/A+A/331/81/table2"
+    cat2 = "blabla"
+    # reproduces #1464
+    with pytest.raises(ValueError, match=f"'{re.escape(cat1)}' is not available *"):
+        xm.query_async(cat1=cat1, cat2=cat2, max_distance=5 * arcsec)